在谷歌地图API中按名称查找纬度/液化边界内的位置



我有一个命名位置列表和一组纬度/液化边界,我想将其插入谷歌地图 API 并让它为我找到位置。名称可能非常模糊,例如简单的"寄宿学校"。使用纬度/液化边界,有没有办法让 GMaps 在提供的坐标内找到这些模糊命名的位置?

我的应用程序是基于Web的,由后端的Python Flask提供支持。我尝试过查看地图的地点搜索,但似乎它只能"首选"某个区域进行搜索,而且由于我模糊的地名,它做得不好:

https://maps.googleapis.com/maps/api/place/findplacefromtext/xml?input=beach&inputtype=textquery&fields=formatted_address,geometry&locationbias=rectangle:43.3145,-79.8236|43.3490,-79.7741&key=XXXXXXX

此查询的偏差覆盖了安大略省伯灵顿的部分地区,但结果是在邻近的奥克维尔镇,明显超出了界限。但是,如果您使用术语"伯灵顿海滩"执行搜索,它会找到范围内的海滩。

我需要查询来查找伯灵顿的海滩,简单地给出术语"海滩",以及所述海滩所属的边界。

编辑:这是我在测试原始查询和埃文的较小查询(评论中的URL(时Chrome和Edge中的HTTP requests+headers:

==== Google Chrome: Original Request ====
:authority: maps.googleapis.com
:method: GET
:path: /maps/api/place/findplacefromtext/json?input=beach&inputtype=textquery&fields=formatted_address,geometry&locationbias=rectangle:43.3145,-79.8236|43.3490,-79.7741&key=
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
accept-encoding: gzip, deflate, br
accept-language: en-CA,en;q=0.9,it;q=0.8,el-GR;q=0.7,el;q=0.6
cache-control: max-age=0
dnt: 1
sec-fetch-mode: navigate
sec-fetch-site: none
sec-fetch-user: ?1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
x-client-data: CIi2yQEIprbJAQjBtskBCKmdygEIup/KAQioo8oBCOKoygEIl63KAQjNrcoBCMqvygEIh7TKARjwsMoB

==== Google Chrome: Evan's Request ====
:authority: maps.googleapis.com
:method: GET
:path: /maps/api/place/findplacefromtext/json?input=beach&inputtype=textquery&fields=formatted_address,geometry&locationbias=rectangle:43.3145,-79.8236|43.3490,-79.800879&key=
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
accept-encoding: gzip, deflate, br
accept-language: en-CA,en;q=0.9,it;q=0.8,el-GR;q=0.7,el;q=0.6
cache-control: max-age=0
dnt: 1
sec-fetch-mode: navigate
sec-fetch-site: none
sec-fetch-user: ?1
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
x-client-data: CIi2yQEIprbJAQjBtskBCKmdygEIup/KAQioo8oBCOKoygEIl63KAQjNrcoBCMqvygEIh7TKARjwsMoB

==== Edge: Original Request ====
Request URL: https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=beach&inputtype=textquery&fields=formatted_address,geometry&locationbias=rectangle:43.3145,-79.8236|43.3490,-79.7741&key=
Request Method: GET
Status Code: 200 /
Accept: text/html, application/xhtml+xml, application/xml; q=0.9, */*; q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-CA
Cache-Control: max-age=0
Host: maps.googleapis.com
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362

==== Edge: Evan's Request ====
Request URL: https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=beach&inputtype=textquery&fields=formatted_address,geometry&locationbias=rectangle:43.3145,-79.8236|43.3490,-79.800879&key=
Request Method: GET
Status Code: 200 /
Accept: text/html, application/xhtml+xml, application/xml; q=0.9, */*; q=0.8
Accept-Encoding: gzip, deflate, br
Accept-Language: en-CA
Host: maps.googleapis.com
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.18362

这种不一致似乎与Google的问题跟踪器中报告的以下问题有关:

https://issuetracker.google.com/issues/35822155

语言参数会影响您从"地点搜索"请求中获得的结果,对于此类通用/广泛查询,情况更是如此。因此,这是 API 的预期行为。

">

查找地点"的潜在替代方案包括使用"附近搜索"或"文本搜索"服务。这些更适合不明确的查询,您可以过滤掉给定半径+位置之外的结果。

希望这有帮助!

相关内容

  • 没有找到相关文章

最新更新