如何在Gmap.net中创建路由wpf?

时间:2016-02-15 10:48:21

标签: c# wpf gmap.net

我希望你能帮助我。对于WPF版本的GMap.net,我在网上找不到任何有用的东西。

问题:我没有看到我的路线。

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

主要问题是,我无法使用GMap.NET教程中的叠加层。

有什么建议吗?

2 个答案:

答案 0 :(得分:4)

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

答案 1 :(得分:1)

一般方法是添加标记并将路线点添加到标记的Route

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