Reputation: 85
I am developing a web page using Google map API v3. Is there a way to collect the place or city names the route is going through to get from point A to B? I am using javascript in the page.
Upvotes: 2
Views: 3867
Reputation: 1535
Check out the Directions API docs. It looks like you are provided with a DirectionsResult
object that contains an array of DirectionsRoute
s. Each DirectionsRoute
contains an array of DirectionsLeg
s, which in turn is broken down even further into a set of DirectionsStep
s. From each step you can pull the start_location
and/or end_location
, each of which is represented as Lat/Lng. From there, I'll let this answer take over on how to convert the Lat/Lng to a city (reverse-geocoding):
Google Maps: how to get country, state/province/region, city given a lat/long value?
In short, the directions Google Maps provided are broken down into many sub sections, and at most levels of granularity you can pull out the latitude/longitude and let Google's geocoding API handle converting that to a city name.
Upvotes: 8