我有一堆GeoCoordinate对象,我希望将其显示为折线(以显示某人所走的路径)。
我的尝试失败(不显示任何行):
var map = new Map(); // Nokia Maps
var layer = new MapLayer();
var overlay = new MapOverlay();
var polyline = new MapPolyline();
var gc = new GeoCoordinateCollection();
foreach(var geo in MyGeoCoordinateList) {
gc.Add(geo);
}
polyline.Path = gc;
polyline.StrokeColors = Colors.Red;
polyline.StrokeThickness = 3;
overlay.Content = polyline;
layer.Add(overlay);
map.Layers.Add(layer);
LayoutRoot.Children.Add(map);
答案 0 :(得分:3)
事实证明,要显示一条路径(简单地连接点并且不像Mike Brown的例子那样遵循道路),您需要将折线添加到MapElements对象,即:
var map = new Map(); // Nokia Maps
var polyline = new MapPolyline();
var gc = new GeoCoordinateCollection();
foreach(var geo in MyGeoCoordinateList) {
gc.Add(geo);
}
polyline.Path = gc;
polyline.StrokeColors = Colors.Red;
polyline.StrokeThickness = 3;
map.MapElements.Add(polyline);
LayoutRoot.Children.Add(map);
作为奖励,这里是如何设置地图,使其包含视口中的点(动画效果很好):
map.SetView(LocationRectangle.CreateBoundingRectangle(MyGeoCoordinateList, MapAnimationKind.Parabolic);
答案 1 :(得分:2)
我想做同样的事情,我使用GeoQuery传递所有的航点。该查询生成了一条路线,然后我在UI上显示。
var query = new RouteQuery();
query.Waypoints = new[]
{
new GeoCoordinate(40.7840553533410,-73.9764425910787),
new GeoCoordinate(40.7833068308611,-73.9745997113487),
new GeoCoordinate(40.7826229881351,-73.9730985576614),
new GeoCoordinate(40.7821147220884,-73.9719513345183),
new GeoCoordinate(40.7809503161196,-73.9724639235822),
new GeoCoordinate(40.7803311395532,-73.9721954245488),
new GeoCoordinate(40.7795640919224,-73.9729398991417),
};
query.TravelMode = TravelMode.Walking;
var result = await query.GetRouteAsync();
var mapRoute = new MapRoute(result);
mapRoute.Color = Colors.Magenta;
mainMap.AddRoute(mapRoute);
mainMap是我UI中的Map控件。该查询创建一条跟随可用路径的路线(因为我将其标记为行走路径,它使用了中央公园的步行路径)。