简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM