首页 > 解决方案 > 谷歌地图地理编码 api 返回无效邮政编码的结果

问题描述

Google 地理编码 API 返回以下邮政编码的结果:“0”、“00”、“000”、“00000”

点击此 api 后 - https://maps.googleapis.com/maps/api/geocode/json?address=00000&key=mysecretkey 它返回“formatted_address”:“6009 Wayzata Blvd Suite #108, St Louis Park, MN 55416, USA "

这些是有效的邮政编码吗?理想情况下,它不应该返回结果。

标签: google-mapsgoogle-geocoding-apizipcode

解决方案


您应该注意以下几点:

  • 当您address=00000在 Geocoding API 请求中发送参数时,它将在格式化的地址或地名中搜索匹配。在这种情况下,服务不会只匹配邮政编码。

  • Google 的数据库中可能有错误的数据,可能会导致意外结果。

在您的示例中,它似乎是 Google 数据库中的错误数据。

让我们看看您的请求的响应

https://maps.googleapis.com/maps/api/geocode/json?address=00000&key=YOUR_API_KEY

正如您在响应中看到的,地点 ID 是“ChIJgyA2iZU0s1IReyHBw0yPjZg”。现在检查此地点 ID 的地点详细信息请求的输出

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

响应将包含以下内容

{
    ....
    id: "3fff72184719b7835304f285f40e677e9914933e",
    international_phone_number: "+1 763-300-8722",
    name: "00000",
    place_id: "ChIJgyA2iZU0s1IReyHBw0yPjZg",
    formatted_address: "6009 Wayzata Blvd Suite #108, St Louis Park, MN 55416, USA",
    types: [
        "lodging",
        "point_of_interest",
        "establishment"
    ],
    .....
} 

请注意,该商家在 Google 数据库中的名称为“00000”,因此 Geocoding API 正在按预期工作,但显然这里存在数据问题。

您可以使用此链接查看该地点并向 Google 报告不良数据

https://maps.google.com/?cid=10992599825345749371

我希望这有帮助!


推荐阅读