How to create a route in Gmap.net wpf?

旧街凉风 提交于 2019-12-12 01:34:45

问题


I hope you can help me. I can not find anything helpful in the web for the WPF version of GMap.net.

Problem: I don't see my route.

List<Location> points = PolylinePoint.Decode(responseData.routes.First().overview_polyline.points);

GMap.NET.WindowsPresentation.GMapRoute route = new GMap.NET.WindowsPresentation.GMapRoute(points.Select(x => new PointLatLng(x.Latitude.Value, x.Longitude.Value)));
route.ZIndex = ROUTESLIST;
route.Shape = new Line() { StrokeThickness = 4, Stroke = System.Windows.Media.Brushes.BlueViolet };
this.routenList.Clear();
this.routenList.Add(route);

The main problem is, that I can not use an overlay like in the GMap.NET tutorials.

Any suggestions?


回答1:


    RoutingProvider routingProvider = 
       _map.MapProvider as RoutingProvider ?? GMapProviders.OpenStreetMap;

    MapRoute route = routingProvider.GetRoute(
        new PointLatLng(35.834914, -76.009508), //start
        new PointLatLng(35.854914, -76.009508), //end
        false, //avoid highways 
        false, //walking mode
        (int)_map.Zoom);

    GMapRoute gmRoute = new GMapRoute(route.Points);

    _map.Markers.Add(gmRoute);



回答2:


The general approach is to add a marker and add the route points to the Route of the marker:

var track = new List<PointLatLng>();

// add PointLatLngs to 'track' here

var routeMarker = new GMapMarker(track.First());
routeMarker.Route.AddRange(track);

// don't forget to add the marker to the map
_mapControl.Markers.Add(routeMarker);


来源:https://stackoverflow.com/questions/35407346/how-to-create-a-route-in-gmap-net-wpf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!