GMap.NET route returns null

I am working on a program with C # and I want to calculate the route, but it returns null.

Here is my code;

PointLatLng start = new PointLatLng(38.481858, 27.089006); PointLatLng end = new PointLatLng(38.468447, 27.113793); MapRoute route = GMap.NET.MapProviders.GoogleMapProvider .Instance.GetRoute(start, end, false, false, 15); GMapRoute r = new GMapRoute(route.Points , "My route"); GMapOverlay routeOverlay = new GMapOverlay("route"); routeOverlay.Routes.Add(r); gMap.Overlays.Add(routeOverlay); double distance; distance = route.Distance; r.Stroke.Width = 2; r.Stroke.Color = Color.OrangeRed; 

I do not know where I am wrong. Any help would be appreciated.

+5
source share
4 answers

The problem is resolved. The reason the route returns null is because the routing service was removed by google.

+4
source
 GDirections ss; var xx = GMapProviders.GoogleMap.GetDirections(out ss, start, end, false, false, false, false, false); GMapRoute r = new GMapRoute(ss.Route, "My route"); 

Try it...

+4
source
  PointLatLng startp = new PointLatLng(-25.974134, 32.593042); PointLatLng endp = new PointLatLng(-25.959048, 32.592827); MapRoute route = BingMapProvider.Instance.GetRoute(startp, endp, false, false, 15); GMapRoute r = new GMapRoute(route.Points,"Myroutes"); GMapOverlay routesOverlay = new GMapOverlay("Myroutes"); routesOverlay.Routes.Add(r); gmap.Overlays.Add(routesOverlay); r.Stroke.Width = 2; r.Stroke.Color = Color.SeaGreen; 

// use BingMapProvider

0
source

Your Api key is not valid. Add GMap from nuget using this code:

  public static double GetDistanceByRoute(double startLat, double startLng, double endLat, double endLng) { GoogleMapProvider.Instance.ApiKey = "Your Api Key"; PointLatLng start = new PointLatLng(startLat, startLng); PointLatLng end = new PointLatLng(endLat, endLng); MapRoute route = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetRoute(start, end, false, false, 15); return route.Distance; } 
0
source

All Articles