GMap.NET C#, distance between 2 points without Google Distance Matrix Api

5.3k views Asked by At

I'm trying to use GMaps in my Windows Form in C#. I have already created the exact route but is there any way to calculate the route's distance and duration in GMaps.NET, is there any function implemented for this purpose besides calling the Google Distance Matrix Api?

1

There are 1 answers

1
HelloIT On BEST ANSWER

The function I was looking for is named "Distance". This is how to obtain route's distance:

            inicial = new PointLatLng(googleGeoCoding(txtorigin.Text).Item2,googleGeoCoding(txtorigin.Text).Item3);

            final = new PointLatLng(googleGeoCoding(txtdest.Text).Item2, googleGeoCoding(txtdest.Text).Item3);


            GDirections routedir;
            var routefromtable = GMapProviders.GoogleMap.GetDirections(out routedir, inicial, final, chbxhighways.Checked, chbxtolls.Checked, rbtnwalking.Checked, false, false);

            GMapRoute tablemaproute = new GMapRoute(routedir.Route, "Ruta ubication");

            GMapOverlay tablerouteoverlay = new GMapOverlay("Capa de la ruta");

            tablerouteoverlay.Routes.Add(tablemaproute);

            gMapControl1.Overlays.Add(tablerouteoverlay);
            gMapControl1.Zoom = gMapControl1.Zoom + 1;
            gMapControl1.Zoom = gMapControl1.Zoom - 1;

            double distance = tablemaproute.Distance;
            MessageBox.Show(distance.ToString());