我正在尝试创建一个具有地图的应用程序,一个“跟随”用户当前位置的MapIcon,并显示从A到B的简单步行路线。
目前我正在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
答案 0 :(得分:0)
至少有一个问题可能是Z-Ordering,因为没有改变z排序的函数,你需要通过以正确的顺序添加对象来实现。
因此,如果你删除&在开始制作路线时从地图中删除人物图标,并构建&将路径添加到地图后,将其添加回来。这样可以确保在路径对象的顶部绘制图标。
我承认我从来没有用路线对象检查这个选项,因此如果它仍然失败,那么我会尝试使用折线逐条绘制路线,然后至少它应该完全正确。