我使用Google Place details API来获取包含地点的纬度/经度坐标的地方详细信息 .
当我使用通用跨平台Maps URL启动Google Map 时,它无法识别Place .
例如,
https://maps.googleapis.com/maps/api/place/details/json?placeid=ChIJbf8C1yFxdDkR3n12P4DkKt0&key=XXXXXXXX
返回地点详细信息,包括以下位置数据:
{
.....
"geometry": {
"location": {
"lat": 27.1750151,
"lng": 78.0421552
},
"viewport": {
"northeast": {
"lat": 27.1770292,
"lng": 78.04537599999999
},
"southwest": {
"lat": 27.16897280000001,
"lng": 78.0388188
}
}
},
.....
"name": "Taj Mahal",
"place_id": "ChIJbf8C1yFxdDkR3n12P4DkKt0",
.....
}
但是,当用于创建带有direction map action的Maps URL时,此数据不会在目标字段中提供正确的位置 .
Google Map 网址:https://www.google.com/maps/dir/?api=1&destination=27.1750151,78.0421552&destination_place_id=ChIJbf8C1yFxdDkR3n12P4DkKt0
目的地不显示为地点 . 仅使用lat / lng或地址,如下所示 .
正确/预期的结果如下 . 看看目的地 .
Update
问题似乎是PlaceID与 Map 网址中的lat / lng坐标不匹配 . Place Details API提供的lat / lng似乎不一致 .
URL下方有效
https://www.google.com/maps/dir/?api=1&destination=27.1750151,78.0421552,15z&destination_place_id=ChIJbf8C1yFxdDkR3n12P4DkKt0
但 27.1750151,78.0421552,15z
不是Place details API的坐标 . PlaceDetails API返回的lat / lng为 27.1750151,78.0421552
.
有一个区别 ,15z
我相信它是zoom levels .
2 回答
当提供lat / lngs时,
destination
参数看起来完全胜过destination_place_id
参数,导致坐标上出现反向地理编码 . 在以下示例URL中,我使用的地方ID为ChIJj61dQgK6j4AR4GeTYWZsKWw
,其对应于山景城中的Googleplex,对应于destination_place_id
以及作为destination
的泰姬陵的纬度/经度 . 注意Googleplex查询被忽略,执行反向地理编码只获取印度的地址:https://www.google.com/maps/dir/?api=1&destination=27.1750151,78.0421552&destination_place_id=ChIJj61dQgK6j4AR4GeTYWZsKWw
因此,解决方法是不使用lat / lng作为
destination
参数 . 我已经使用各种字符串(地名,地址,乱码)作为该参数进行了测试,并且destination_place_id
似乎取代了它,这是所需的行为 . 仅使用.
(句点)作为通用值时,会提供地点名称和地址:https://www.google.com/maps/dir/?api=1&destination=.&destination_place_id=ChIJj61dQgK6j4AR4GeTYWZsKWw
https://www.google.com/maps/dir/?api=1&destination=.&destination_place_id=ChIJbf8C1yFxdDkR3n12P4DkKt0
该文档提到
destination
该值可以是地名,地址或以逗号分隔的纬度/经度坐标 .如果你输入坐标,我想它只是做一个反向地理编码并显示相应的地址 . 所以你可以输入地名,它会起作用 .
https://www.google.com/maps/dir/?api=1&destination=Taj+Mahal&destination_place_id=ChIJbf8C1yFxdDkR3n12P4DkKt0