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

javascript - Google maps API: Search for nearest train station? - Stack Overflow

programmeradmin6浏览0评论

I would like to automate the process of finding the closest train station's name to a given address (server side).

To state it another way, I would like to write a function that given any location string X, it returns the station name string Y.

I have experience with google map's API but I have not found a way to do this.

Just the name is enough information, but any amount of information or a list of the closest stations is OK, as long as I can confirm the closest one on the list.

I would like to automate the process of finding the closest train station's name to a given address (server side).

To state it another way, I would like to write a function that given any location string X, it returns the station name string Y.

I have experience with google map's API but I have not found a way to do this.

Just the name is enough information, but any amount of information or a list of the closest stations is OK, as long as I can confirm the closest one on the list.

Share Improve this question edited Jul 1, 2018 at 10:14 xomena 32.2k6 gold badges96 silver badges125 bronze badges asked May 13, 2018 at 5:43 Andy MacAndy Mac 3792 silver badges9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

You can use a Places API web service to get nearest train station. For this purpose you can use nearby search functionality. For example, I have coordinate 45.77940539999999,15.9516292 and want to find a nearest train station.

Using web service request

https://maps.googleapis./maps/api/place/nearbysearch/json?location=45.77940539999999%2C15.9516292&rankby=distance&type=train_station&key=YOUR_API_KEY

you will get the nearest train station with name Remetinec as shown in my screenshot

As your intention is to implement this in server-side NodeJs, you can use the Node.js client library for Google Maps API Web Services

https://github./googlemaps/google-maps-services-js

The documentation is located at

https://googlemaps.github.io/google-maps-services-js/docs/GoogleMapsClient.html

Have a look at the placesNearby(query, callback) method.

I hope this helps!

发布评论

评论列表(0)

  1. 暂无评论