Displaying a polyline of geo-coordinate objects

I have a bunch of GeoCoordinate objects that I want to display as a polyline (to show the path that a person took).

My unsuccessful attempt (does not display the string):

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); 
+4
source share
2 answers

I wanted to do the same, I used GeoQuery, passing in all waypoints. The request generated a route, which I then displayed in the user interface.

 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 is a Map control in my user interface. The request creates a route following the accessible path (since I designated it as a foot path, he used foot paths in the central park).

+2
source

It turns out that to display the path (which simply connects the points and does not follow the roads, as in the example of Mike Brown) you need to add a polyline to the MapElements object, that is:

 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); 

As a bonus here, how to install a map so that it contains dots in the presentation port (with nice animation):

 map.SetView(LocationRectangle.CreateBoundingRectangle(MyGeoCoordinateList, MapAnimationKind.Parabolic); 
+3
source

All Articles