Google 地点 API - 返回无效的街道号码

Google Places API - Returning invalid street numbers

如果我搜索 500 Buckingham Place, Eight Mile Plains Google 个地点 API returns 500 Buckingham Place, Eight Mile Plains, Queensland, Australia,地点 ID Ej41MDAgQnVja2luZ2hhbSBQbGFjZSwgRWlnaHQgTWlsZSBQbGFpbnMsIFF1ZWVuc2xhbmQsIEF1c3RyYWxpYQ。如果我随后对该地点 ID 进行详细调用,它 returns Buckingham Pl, Eight Mile Plains QLD 4113, Australia.

这可以在 Google 地图网站 https://www.google.com.au/maps/search/500+Buckingham+Place+Eight+Mile+Plains 上复制。 returned 的位置将只是 Buckingham Pl, Eight Mile Plains QLD 4113, Australia.

我能否将 Google 地点 API 仅用于 return 实际街道号码的搜索结果?

编辑 我打的电话是https://maps.googleapis.com/maps/api/place/autocomplete/json?input=500%20Buckingham%20Place%2C%20Eight%20Mile%20Plains&types=address

来自 google map api doc:

Addresses are returned in the order of best to least matches. Generally, the more exact address is the most prominent result, as it is in this case. Note that we return different types of addresses, from the most specific street address to less specific political entities such as neighborhoods, cities, counties, states, etc.

所以问题是,当您添加一个不存在的街道号码时,没有完全匹配 return。以下是查找答案是否不完全匹配的方法:

再次 google doc

partial_match indicates that the geocoder did not return an exact match for the original request, though it was able to match part of the requested address.

如果你做一些测试,你会发现当街道号码不存在时(或者地址无效或者你没有为唯一地址提供足够的信息)它 return 一个变量partial_match:true 和一个或多个接近的匹配项,如图所示。

我用自动完成和地理编码器做了一个简单的例子:http://jsfiddle.net/TomKarachristos/qLyrj38d/, 当 partial_match 为真时 return "not a valid result"

if (results[0].partial_match) {
  htmlContent = "not a valid result";
  } else {
  [...]
}

注意:google地图的数据可能不会100%准确。