Using the Google Maps API to find routes and the distance between two points and present them in a table

I want to use Google maps to find available routes between two cities. Some information about these routes, such as distance and travel time, etc.

I do not want this data to be presented on the Map. I need this to be presented to the end user in text format.

The user will give me two cities, and I will present him with various routes and information in the table.

Can this be done using PHP, MySQL and Google Maps? Any pointers would be very helpful.

+4
source share
2 answers

If you need multiple routes between two points, use the route service (http://code.google.com/apis/maps/documentation/directions) and specify alternatives=true in the request. This will return alternative routes, if available. Then analyze the response to the required information:

  • there will be one legs array for each route
  • inside this legs array there is a distance and duration field, each of which contains the original value and a text value.

If you don’t need multiple route options, the Google Maps Distance Matrix service (http://code.google.com/apis/maps/documentation/distancematrix/) provides distance and travel time between multiple sources and destinations, without information about all directions.

A sample table is in the blog post: http://googlegeodevelopers.blogspot.com/2011/05/what-is-distance-matrix.html

+4
source

Google Maps Direction Service can provide you with textual information. See the documentation here: http://code.google.com/apis/maps/documentation/javascript/services.html#Directions In particular, the beginning of the bit "A DirectionsRenderer not only handles the display of the polyline and any associated markers, but it can also process text showing directions as a sequence of steps, just call setPanel () on your DirectionsRenderer, passing it to display this information.

+1
source

Source: https://habr.com/ru/post/1379096/


All Articles