MapPolyline没有被绘制

我试图在我的Map中使用MapPolyLine来显示实时路线,希望它会在这个时间移动/缩放。 事情是地图上没有显示该行,我找不到任何编程错误:

C#

MapLayer pathLayer; //Constructor pathLayer = new MapLayer(); MapPolyline line = new MapPolyline(); line.StrokeColor = Colors.Red; line.StrokeThickness = 10; //line.Path.Add(several points); Tested, no effect MapOverlay overlay = new MapOverlay(); overlay.Content = line; //overlay.GeoCoordinate = new GeoCoordinate(0,0); Tested, no effect //overlay.PositionOrigin = new Point(0.0, 1.0); Tested, no effect pathLayer.Add(overlay); MyMap.Layers.Add(pathLayer); void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args) { MapPolyline line = pathLayer.First(TrackPath).Content as MapPolyline; line.Path.Add(args.Position.Coordinate); // Checked values, line.Path adds them correctly } 

编辑:新信息。 尝试使用XAML添加模拟器时,模拟器显示错误,模拟器将地图顶部的类名称显示为图形故障:

模拟器错误在顶部,XAML在右侧

MapPolylinesMapPolygons添加到MapElements集合中…而MapLayerMapOverlay

您应该能够使此示例适合您。

  MapPolyline line = new MapPolyline(); line.StrokeColor = Colors.Red; line.StrokeThickness = 10; line.Path.Add(new GeoCoordinate(47.6602, -122.098358)); line.Path.Add(new GeoCoordinate(47.561482, -122.071544)); MyMap.MapElements.Add(line); 

在你的GeoCoord观察者中,你必须从地图的MapElements集合中获取该行,并将新位置添加到行的路径而不是像我那样预定义。 这应该是可行的。

在Windows Phone 8.1中,尝试以这种方式添加点。 “punkty”是我的collections。

  List PosList = new List(); foreach (var item in punkty) { PosList.Add(new BasicGeoposition() { Latitude = item.Position.Latitude, Longitude = item.Position.Longitude }); } //Example of one point //PosList.Add(new BasicGeoposition() //{ // Latitude = 52.46479093, // Longitude = 16.91743341 //}); MapPolyline line = new MapPolyline(); line.StrokeColor = Colors.Red; line.StrokeThickness = 5; line.Path = new Geopath(PosList); myMap.MapElements.Add(line);