gpt4 book ai didi

javascript - 谷歌地图 API : Search for nearest train station?

转载 作者:搜寻专家 更新时间:2023-10-31 23:50:44 26 4
gpt4 key购买 nike

我想自动查找距离给定地址最近的火车站名称(服务器端)。

换句话说,我想编写一个函数,给定任何位置字符串 X,它返回站名字符串 Y。

我有使用谷歌地图 API 的经验,但我还没有找到执行此操作的方法。

只要名称就足够了,但任何数量的信息或最近的车站列表都可以,只要我能确认列表中最近的一个。

最佳答案

您可以使用 Places API 网络服务获取最近的火车站。为此,您可以使用附近的搜索功能。例如,我有坐标 45.77940539999999,15.9516292 并想找到最近的火车站。

使用 web service要求

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

如我的屏幕截图所示,您将找到最近的名为 Remetinec 的火车站

enter image description here

由于您的意图是在服务器端 NodeJs 中实现这一点,因此您可以将 Node.js 客户端库用于 Google Maps API Web 服务

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

文档位于

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

看看 placesNearby(query, callback) 方法。

希望对您有所帮助!

关于javascript - 谷歌地图 API : Search for nearest train station?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50313126/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com