Google 地点详情 Lat/Long 坐标与跨平台地图网址不匹配

Google Place Details Lat/Long coordinates not matching cross platform Maps URLs

我已经使用 Google Place details API 获取地点详细信息,其中包括地点的 lat/lng 坐标。

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

例如,

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

returns 包含以下位置数据的地点详细信息:

 {
  .....
  "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时,并未在目标字段中给出正确的位置。

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

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

correct/expected 结果如下。看看目的地。

更新

问题似乎在于 PlaceID 与地图 URL 中的 lat/lng 坐标不匹配。地点详情 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

文档提到 destination 该值可以是地名、地址或 comma-separated latitude/longitude 坐标。

如果您输入坐标,我想它只是进行反向地理编码并显示相应的地址。所以你输入地名就可以了

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

当提供 lat/lngs 时,destination 参数看起来完全胜过 destination_place_id 参数,导致坐标上的反向地理编码。在以下示例 URL 中,我使用 ChIJj61dQgK6j4AR4GeTYWZsKWw 的地点 ID,它对应于加利福尼亚州山景城的 Googleplex 作为 destination_place_id 以及 lat/lng泰姬陵作为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