gpt4 book ai didi

javascript - Google Places API - 返回无效的街道号码

转载 作者:搜寻专家 更新时间:2023-11-01 04:14:46 24 4
gpt4 key购买 nike

如果我搜索 500 Buckingham Place, Eight Mile Plains,Google Places API 会返回 500 Buckingham Place, Eight Mile Plains, Queensland, Australia 以及地点 ID Ej41MDAgQnVja2luZ2hhbSBQbGFjZSwgRWlnaHQgTWlsZSBQbGFpbnMsIFF1ZWVuc2xhbmQsIEF1c3RyYWxpYQ。如果我随后对该地点 ID 进行详细信息调用,它会返回 Buckingham Pl, Eight Mile Plains QLD 4113, Australia

这可以在 Google map 网站上复制,网址为 https://www.google.com.au/maps/search/500+Buckingham+Place+Eight+Mile+Plains .返回的地点将只是 Buckingham Pl, Eight Mile Plains QLD 4113, Australia

我能否让 Google Places API 仅返回实际街道号码的搜索结果?

编辑我打的电话是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.

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

再次出现在 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.

如果你做了一些测试,你会发现当街道号码不存在时(或者地址无效或者你没有为唯一地址提供足够的信息)它返回一个变量 partial_match:true 和一个或更接近的比赛,就像图片一样。 enter image description here

我用自动完成和地理编码器做了一个简单的例子:http://jsfiddle.net/TomKarachristos/qLyrj38d/ ,当 partial_match 为真时,它返回“无效结果”

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

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

关于javascript - Google Places API - 返回无效的街道号码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36683097/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com