GMap.NET C#,没有谷歌距离矩阵Api的2点之间的距离

时间:2016-12-27 14:39:17

标签: c# .net google-maps gmap.net

我正在尝试在C#中的Windows窗体中使用GMaps。我已经创建了确切的路线但是有没有办法计算GMaps.NET中路线的距离和持续时间,除了调用Google Distance Matrix Api之外,还有为此目的实现的功能吗?

1 个答案:

答案 0 :(得分:1)

我正在寻找的功能名为“距离”。 这是获取路线距离的方法:

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