google-maps - 使用地点 ID 查找距离

标签 google-maps google-distancematrix-api

根据文档,我们通过以下方式(服务器 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

https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJ2eUgeAK6j4ARbn5u_wAGqWA&key=MYKEY

更新

现在您可以在距离矩阵 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/

相关文章:

android - 尽管有投影,谷歌地图仍绘制正方形

java - 双 Android map /Google 地点详细信息屏幕

Android 谷歌地图 v2. getMapAsync() 不在单独的线程中运行?

google-maps - 包含 2 个以上元素的 Google map 距离矩阵返回 OVER_QUERY_LIMIT

python - 谷歌距离矩阵 API : How to specify origin-destination pairs?

javascript - 谷歌地图需要很长时间才能加载

python - 如何使用 python pygmaps 将 'title' 添加到 Google map 上映射的每个点?

python - 使用请求从谷歌距离矩阵 api 获取响应时出现连接错误

android - 两个地点之间的距离(不显示 map )

javascript - 如何在距离矩阵Google API服务中输入客户端ID或API key