Google Place详细信息Lat / Long坐标与跨平台地图网址不匹配

时间:2018-04-01 11:27:13

标签: google-maps google-maps-api-3 google-places-api

我使用了Google Place details API来获取包含地点的纬度/经度坐标的地方详情。

当我使用通用跨平台Maps URL启动Google地图时,它无法识别该地点。

例如,

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",

  .....
}

但是,当用于创建Maps URL direction map action时,此数据无法在目标字段中显示正确的位置。

Google地图网址:https://www.google.com/maps/dir/?api=1&destination=27.1750151,78.0421552&destination_place_id=ChIJbf8C1yFxdDkR3n12P4DkKt0

目的地未显示为地点。只使用lat / lng或地址,如下所示。

Google Map URL with directions action

正确/预期的结果如下。看看目的地。

The Expected result of opening the Maps URL

更新

问题似乎是PlaceID与地图网址中的lat / lng坐标不匹配。 Place Details API提供的lat / lng似乎不一致。

以下网址

  

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 个答案:

答案 0 :(得分:2)

文档提及destination 该值可以是地名,地址或以逗号分隔的纬度/经度坐标。

如果您输入坐标,我认为它只是执行反向地理编码并显示相应的地址。所以你可以输入地名,它会起作用。

https://www.google.com/maps/dir/?api=1&destination=Taj+Mahal&destination_place_id=ChIJbf8C1yFxdDkR3n12P4DkKt0

答案 1 :(得分:2)

当提供lat / lngs时,destination参数看起来完全胜过destination_place_id参数,导致坐标上出现反向地理编码。在以下示例网址中,我使用ChIJj61dQgK6j4AR4GeTYWZsKWw的地方ID,其对应于Mountain View,CA中的Googleplex作为destination_place_id以及作为Taj Mahal的lat / lng destination;请注意忽略Googleplex查询,并执行反向地理编码,只获取印度的地址:

https://www.google.com/maps/dir/?api=1&destination=27.1750151,78.0421552&destination_place_id=ChIJj61dQgK6j4AR4GeTYWZsKWw

enter image description here

因此,解决方法是不使用lat / lng作为destination参数。我已经使用各种字符串(地名,地址,乱码)作为该参数进行了测试,destination_place_id似乎取代了它,这是所需的行为。仅使用.(句点)作为通用值时,会提供地点名称和地址:

https://www.google.com/maps/dir/?api=1&destination=.&destination_place_id=ChIJj61dQgK6j4AR4GeTYWZsKWw

enter image description here

https://www.google.com/maps/dir/?api=1&destination=.&destination_place_id=ChIJbf8C1yFxdDkR3n12P4DkKt0

enter image description here

相关问题