Gmap不显示C#中两点之间的路线

时间:2019-08-22 01:52:32

标签: c# routes coordinates gmap.net

我在我的应用程序c#中实现了一个gmap,我有两点。问题是我找到了可以路由这两个点的代码,但是它不起作用。

 List<PointLatLng> _point;

 gMapControl1.ShowCenter = false;
 _point = new List<PointLatLng>();

 private void RiversMap_Load(object sender, EventArgs e)
    {
        gMapControl1.MapProvider = GMapProviders.GoogleMap;
        GMaps.Instance.Mode = AccessMode.ServerAndCache;
        GMapProviders.GoogleMap.ApiKey = @"abcdefghijklnop12344";
        _point.Add(new PointLatLng(headlatitude, headlongitude));
        _point.Add(new PointLatLng(headlatitude, headlongitude));
    }

这是我要选两个点的事件

 private void Button2_Click(object sender, EventArgs e)
   {
        var route = GoogleMapProvider.Instance.GetRoute(_point[0],_point[1], false, false, 14);
        var r = new GMapRoute(route.Points, " My route");
        var routes = new GMapOverlay("routes");
        routes.Routes.Add(r);
        gMapControl1.Overlays.Add(routes);
        gMapControl1.UpdateRouteLocalPosition(r);


   }

有时它给我一个错误,它说

 routes was null

0 个答案:

没有答案