最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - get the city names the google map route going through - Stack Overflow

programmeradmin2浏览0评论

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.

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.

Share Improve this question asked Jan 13, 2013 at 2:53 Infoglaze.Infoglaze. 852 silver badges3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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.

发布评论

评论列表(0)

  1. 暂无评论