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.
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!
The API returns information based on the recommended route between start and end points. You can request distance data for different travel modes, request distance data in different units such kilometers or miles, and estimate travel time in traffic.
The formula for calculating longitude distance is: "Dep = d. long * Cos Mid. Lat" Dep is the same thing as miles.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With