Google 地图 API - 地理编码 - Postman 得到 ZERO_RESULTS vs 浏览器得到 OK

Google Maps API - Geocode - Postman get ZERO_RESULTS vs Browser get OK

要求:

https://maps.googleapis.com/maps/api/geocode/json?address=TV%20FRANCISCO%20VIGNOLI%2C%2053%2C%20CENTRO&components=administrative_area:SAQUAREMA|administrative_area:RJ|country:br&key=YOUR_API_KEY

得到结果:

{ "results": [], "status": "ZERO_RESULTS" }

但是当我使用浏览器时得到"status": "OK"

我是不是漏掉了什么?

Your link 在浏览器中对我不起作用(当我添加自己的密钥时)。

看起来 Geocoder 知道的地址是:

Tv. Francisco Vignole, 53 - Campo Aviacao, Saquarema - RJ, 28990-000, Brazil

This request 适用于我的浏览器和邮递员(当我添加密钥时):

https://maps.googleapis.com/maps/api/geocode/json?address=Francisco%20Vignole,53%20Campo%20Aviacao&components=administrative_area:SAQUAREMA|administrative_area:RJ|country:br&key=

我认为诀窍在于您的浏览器在请求中添加了一些额外信息 headers。例如,浏览器可能知道您的区域设置和语言,因此添加此信息可能有助于 Google 使结果偏向特定区域。

可能 TV FRANCISCO VIGNOLI, 53, CENTRO 不会为说英语的人带来任何相关结果,但它可以找到与说葡萄牙语的用户相关的内容。

在你的例子中,如果我从邮递员那里执行查询

https://maps.googleapis.com/maps/api/geocode/json?address=TV%20FRANCISCO%20VIGNOLI%2C%2053%2C%20CENTRO&key=MY_API_KEY

我得到 ZERO_RESULTS。

但是如果我在请求中添加区域参数并且结果偏向巴西

https://maps.googleapis.com/maps/api/geocode/json?address=TV%20FRANCISCO%20VIGNOLI%2C%2053%2C%20CENTRO&region=BR&key=MY_API_KEY

我收到回复

{
  "results":[
    {
      "address_components":[
    {
      "long_name":"LOJA 01",
      "short_name":"LOJA 01",
      "types":[
        "subpremise"
      ]
    },
    {
      "long_name":"53",
      "short_name":"53",
      "types":[
        "street_number"
      ]
    },
    {
      "long_name":"Tv Francisco Vignoli",
      "short_name":"Tv Francisco Vignoli",
      "types":[
        "route"
      ]
    },
    {
      "long_name":"Centro",
      "short_name":"Centro",
      "types":[
        "political","sublocality","sublocality_level_1"
      ]
    },
    {
      "long_name":"Saquarema",
      "short_name":"Saquarema",
      "types":[
        "administrative_area_level_2","political"
      ]
    },
    {
      "long_name":"Rio de Janeiro",
      "short_name":"RJ",
      "types":[
        "administrative_area_level_1","political"
      ]
    },
    {
      "long_name":"Brazil",
      "short_name":"BR",
      "types":[
        "country","political"
      ]
    },
    {
      "long_name":"28990-774",
      "short_name":"28990-774",
      "types":[
        "postal_code"
      ]
    }
      ],
      "formatted_address":"Tv Francisco Vignoli, 53 - LOJA 01 - Centro, Saquarema - RJ, 28990-774, Brazil",
      "geometry":{
    "location":{
      "lat":-22.9325062,"lng":-42.4960983
    },
    "location_type":"ROOFTOP",
    "viewport":{
      "northeast":{
        "lat":-22.9311572197085,"lng":-42.4947493197085
      },
      "southwest":{
        "lat":-22.9338551802915,"lng":-42.4974472802915
      }
    }
      },
      "place_id":"ChIJbZ-VwgNflwARDpn0-ZA19Xs",
      "plus_code":{
    "compound_code":"3G83+XH Centro, Saquarema - State of Rio de Janeiro, Brazil","global_code":"589V3G83+XH"
      },
      "types":[
    "establishment","health","point_of_interest","store"
      ]
    }
  ],
  "status":"OK"
}

此时您的浏览器似乎足够智能,可以将区域信息发送到 Google 后端服务器。

希望我的回答能解开你的疑惑。

你需要设置你Accept-Languageheader 'Accept-Language'=>'Fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3' 此处有更多信息 https://developers.google.com/maps/documentation/javascript/localization