根据文档,我们通过以下方式(服务器 API)检索一组起点和终点之间的距离。
https://maps.googleapis.com/maps/api/distancematrix/json?origins=Washington%20DC&destinations=New%20York&mode=walking&key=
与其传递地名,不如传递 place_id 作为起点或终点。这将给出更准确的结果。有可能吗?
例如。是否可以执行如下 API 调用:
https://maps.googleapis.com/maps/api/distancematrix/json?origins=<place_id>&destinations=<place_id>&mode=walking&key=
???
谢谢
最佳答案
没有办法让谷歌在谷歌地图方向 API 中使用 place_id 作为起点或目的地。
因此,您这样做的唯一方法是首先从 place_id 获取 lat/lng 或地址。你可以这样做:
1) 反向地理编码:https://developers.google.com/maps/documentation/geocoding/
https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJ2eUgeAK6j4ARbn5u_wAGqWA&key=MYKEY
2) 地点详情:https://developers.google.com/places/webservice/details
更新
现在您可以在距离矩阵 API 中应用地点 ID 作为起点和终点。
If you supply a place ID, you must prefix it with place_id:. You can only specify a place ID if the request includes an API key or a Google Maps APIs Premium Plan client ID.
请参阅文档了解更多详情:
https://developers.google.com/maps/documentation/distance-matrix/intro#RequestParameters
关于google-maps - 使用地点 ID 查找距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31172642/