Infoglaze.com
Infoglaze.com

Reputation: 85

get the city names the google map route going through

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

Answers (1)

Cecchi
Cecchi

Reputation: 1535

Check out the Directions API docs. It looks like you are provided with a DirectionsResult object that contains an array of DirectionsRoutes. Each DirectionsRoute contains an array of DirectionsLegs, which in turn is broken down even further into a set of DirectionsSteps. 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

Related Questions