Question

I have a bunch of GeoCoordinate objects that I wish to display as a polyline (to show a path a person has taken).

My unsuccessful attempt (Does not display any line):

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);
Was it helpful?

Solution 2

I wanted to do the same thing, I used a GeoQuery passing in all of the waypoints. The query generated a route that I then displayed on the 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 is the Map control in my UI. The query creates a route that follows the available path (since I marked it as a walking path, it used the foot paths in central park).

OTHER TIPS

It turns out that to display a path (which simply connects points and does not follow roads like in Mike Brown's example) you need to add the polyline to a MapElements object, i.e:

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's how to set the map so it contains the points in the view port (with nice animation):

map.SetView(LocationRectangle.CreateBoundingRectangle(MyGeoCoordinateList, MapAnimationKind.Parabolic);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top