Google地图API - 沿经纬度之间的路线获取点数 [英] Google Maps API - Get points along route between lat/long

查看:191
本文介绍了Google地图API - 沿经纬度之间的路线获取点数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网站,我正试图完成,我需要让用户点击地图上的点,然后找出两点之间道路上的路线。因此,用户点击第一条街道上的第一个点,然后单击第四条街道上的另一个点,地图将找到最佳方式到达并在地图上绘制路线。我假设这可以通过使用方向和解析它,但我一直在寻找一个小时,无法找到我在找什么(也许是坏的搜索条件)。我需要手动绘制地图(?),以便在用户继续点击时计算路线的距离等。

I have a web site that I am trying to get completed and I need to have the user click points on a map and then work out the route on the roads between the two points. So the user clicks the first point on 1st street, and then clicks another point on 4th street, and the map will find the best way to get there and plot the route on the map. I am assuming this can be done using directions and parse it up, but I have been searching for an hour now and can't find what I am looking for (maybe bad search terms). I need to be able to plot the map manually (?) so I can calculate the distance, etc... of the route as the user continues to click.

在测试版网站是 http://www.RunMyRoute.com/UserRoutes/Create 和你可以看到我正在尝试创建跑步路线。我希望用户可以选择路线跟随道路,而不是地图上两点之间的直线。

The site that is in beta is http://www.RunMyRoute.com/UserRoutes/Create and you can see I am trying to create running routes. I want the user to have the option for the route to follow the roads versus just a straight line between two points on the map.

任何帮助都很棒!

推荐答案

directions.load("from:" + lat1+ ", " + lng1+ " to:" + lat2 + "," + lng2, { getPolyline: true, getSteps: true });

var poly;

GEvent.addListener(directions, "load", function() {
      if (poly) map.removeOverlay(poly);
      poly = directions.getPolyline();
      map.addOverlay(poly);
});

这篇关于Google地图API - 沿经纬度之间的路线获取点数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆