0
我試圖創建具有地圖的應用程序,即「跟隨」用戶的當前位置和MapIcon顯示從一個簡單的行走路線B.MapIcon和路線 - MapIcon消失時的路線
目前我正在WP8.1模擬器上測試它,一切工作都很好,除非我嘗試在顯示的路線上「走路」。圖標消失,如果我離開路線,圖標再次出現。
下面是與此操作相關的代碼和一些顯示意外結果的屏幕截圖。
由於隱私原因,位置被隱藏。
Private geolocator As New Geolocator
Public Async Function IniciarGPS() As Task
map.Language = "pt-PT"
Dim waypoints As New List(Of Geopoint)
waypoints.Add(New Geopoint(New BasicGeoposition With {
.Latitude = 0.0,
.Longitude = -0.0
}))
waypoints.Add(New Geopoint(New BasicGeoposition With {
.Latitude = 0.0,
.Longitude = -0.0
}))
Dim r As MapRouteFinderResult = Await MapRouteFinder.GetWalkingRouteFromWaypointsAsync(waypoints)
If r.Status = MapRouteFinderStatus.Success Then
Dim route As MapRoute = r.Route
Dim mapRouteView As New MapRouteView(route)
mapRouteView.RouteColor = Colors.Black
map.Routes.Add(mapRouteView)
End If
geolocator.DesiredAccuracy = PositionAccuracy.High
geolocator.MovementThreshold = 10
AddHandler geolocator.PositionChanged, AddressOf geolocator_PositionChanged
End Function
Private mIcon As MapIcon = Nothing
Private Async Sub geolocator_PositionChanged(ByVal sender As Object, ByVal e As PositionChangedEventArgs)
Await map.TrySetViewAsync(e.Position.Coordinate.Point, 18, 0, 0, MapAnimationKind.Bow)
Await Me.Dispatcher.RunAsync(CoreDispatcherPriority.High,
Sub()
If mIcon Is Nothing Then
mIcon = New MapIcon()
mIcon.Image =
RandomAccessStreamReference.CreateFromUri(
New Uri("ms-appx:///Assets/Map/map_icon.png")
)
mIcon.Title = "EU"
mIcon.NormalizedAnchorPoint = New Point(0.5, 0.5)
map.MapElements.Add(mIcon)
End If
mIcon.Location = New Geopoint(New BasicGeoposition() With {
.Latitude = e.Position.Coordinate.Point.Position.Latitude,
.Longitude = e.Position.Coordinate.Point.Position.Longitude
})
End Sub)
End Sub
這是我必須嘗試的一件事。目前,我正在重新計算每個已更改位置的路線,以便路線的開始位置是用戶的當前位置。我將不得不等待繪製路線,然後繪製MapIcon。感謝這個想法,一旦我得到時間,我會公佈結果。 – silentw