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