I want to use Google maps to find out available routes between two cities. Some information about these routes like distance and travel time etc.
I do not want this data to be presented in a Map. I need this to be presented to end user in textual format.
User will give me two cities and I will present him with various routes and information in a table.
Can this be done using PHP, MySQL and Google Maps? Any pointers would be very helpful.
Best Answer
If you want multiple routes between two points, use the directions service (http://code.google.com/apis/maps/documentation/directions) and specify
alternatives=true
in the request. This will return alternate routes, if they're available. Then, parse the response for the desired information:legs
array for each routelegs
array, there is adistance
and aduration
field, each containing a raw value and a textual value.If you don't need multiple choices for the route, the Google Maps Distance Matrix service (http://code.google.com/apis/maps/documentation/distancematrix/) provides travel distance and time between multiple origins and destinations, without all of the directions information.
A sample table is in the blog post: http://googlegeodevelopers.blogspot.com/2011/05/what-is-distance-matrix.html