Adding route to map

Topics: General, Windows Forms
Mar 12, 2013 at 7:52 PM
I am making a desktop application to display route between two locations.

I have followed many links relating to same subject but still couldnt find ans.

I have added overly to map.

Kinldy help

            gmap.MapProvider = GMap.NET.MapProviders.GoogleMapProvider.Instance;
            GMap.NET.GMaps.Instance.Mode = GMap.NET.AccessMode.ServerOnly;
            //gmap.Position = new PointLatLng(-25.974134, 32.593042);
            string start = "Delhi";
            string end = "Noida"; 
            MapRoute route = GMap.NET.MapProviders.GoogleMapProvider.Instance.GetRoute(
              start, end, false, false, 15);
            
            
            GMapRoute r = new GMapRoute(route.Points, "My route");
            r.Stroke.Width = 5;
            r.Stroke.Color = Color.Black;

            GMapOverlay routesOverlay = new GMapOverlay("routes");
            routesOverlay.Routes.Add(r);
            gmap.ZoomAndCenterRoute(r);
            gmap.Overlays.Clear();
            gmap.Overlays.Add(routesOverlay);
Mar 12, 2013 at 8:17 PM
it should work
Mar 13, 2013 at 12:15 AM
Edited Mar 13, 2013 at 12:22 AM
But it isn't working.

I am just seeing a map centered at route without route.

Image

What I have done:
  1. Created a new c# project.
  2. Reference dll files of Gmap.net
  3. in design I dragged and drop GmapControl to form.
  4. Renamed form to gmap.
  5. Copy-pasted this code to Form1_Load
  6. Fixed imports.
  7. Run.
Why doesnt it work.

I have checked properties of gmap. RoutesEnabled is set to true.

Do i need to make any other changes
Mar 13, 2013 at 1:18 AM
Try this (assuming you have "gmap" as your GMapControl)
        gmap.MapProvider = GMap.NET.MapProviders.GoogleMap;
        gmap.Manager.Mode = AccessMode.ServerOnly;

        string start = "Delhi";
        string end = "Noida"; 
        MapRoute route = GMapProviders.GoogleMap.GetRouteBetweenPoints(
          start, end, false, false, 15);


        GMapRoute r = new GMapRoute(route.Points, "My route");
        r.Stroke.Width = 5;
        r.Stroke.Color = Color.Black;

        GMapOverlay routesOverlay = new GMapOverlay("routes");
        routesOverlay.Routes.Add(r);
        gmap.Overlays.Add(routesOverlay);
        gmap.ZoomAndCenterMarkers("My route");
As you will learn from the forum here is that not many peeps will take the time to show you "simple" things. Questions will likely get ignored if they think it's not important to help. Hopefully things will change to make this a better environment for both beginners and experts alike.

All great minds start from a blank :) Helping others to achieve their potential contribution to community should be a top priority.
Mar 13, 2013 at 1:29 AM
Sorry. You need to pass the gmap to the GMapOverLay constructor.

This line: GMapOverlay routesOverlay = new GMapOverlay("routes");

Should be : GMapOverlay routesOverlay = new GMapOverlay(gmap, "routes");
Mar 13, 2013 at 1:43 PM
aministrator2000 wrote:
Sorry. You need to pass the gmap to the GMapOverLay constructor.

This line: GMapOverlay routesOverlay = new GMapOverlay("routes");

Should be : GMapOverlay routesOverlay = new GMapOverlay(gmap, "routes");
Sorry to bother again.

Which version are you using.

I am using VS2010 and the latest hotbuild.

When I use your code it doesn't compuile
  1. Errors:
  2. Error 1 The type or namespace name 'GoogleMap' does not exist in the namespace 'GMap.NET.MapProviders' (are you missing an assembly reference?)
  3. Error 2 The name 'GMapProviders' does not exist in the current context
  4. Error 3 The best overloaded method match for 'GMap.NET.WindowsForms.GMapOverlay.GMapOverlay(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)' has some invalid arguments
  5. Error 4 Argument 1: cannot convert from 'GMap.NET.WindowsForms.GMapControl' to 'System.Runtime.Serialization.SerializationInfo'
  6. Error 5 Argument 2: cannot convert from 'string' to 'System.Runtime.Serialization.StreamingContext'
Mar 13, 2013 at 3:49 PM
..you are doing something over-complicated, try check the demo source first
Mar 13, 2013 at 4:13 PM
I am using VS2010 with GMap.net 1.6.

I thought 1.6 is the stable version and the other one is Beta. I did not try out the Beta as the name suggest it might not have everything working correctly. Here is the full path for GoogleMap

GMap.NET.MapProviders.GMapProviders.GoogleMap

This is where I get my Overlay class

GMap.NET.WindowsForms.GMapOverlay

Why are you getting Serialization problem?
Mar 13, 2013 at 6:59 PM
1.6 is actually old version, beta is stable enough