开发者

Google Maps API - Get points along route between lat/long

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... o开发者_Go百科f the route as the user continues to click.

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.

Any help on this would be great!


I had a quick look at the Google Maps API and it looks like you can create a GDirections object to find a route between points and then you can get a PolyLine of the route or things like duration and distance.


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);
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜