我正在尝试将搜索结果限制到某个国家/地区,并将它们严重偏向特定的纬度/经度(但不限制)。
我使用“边界”字段将 API 返回的搜索结果偏向于用户的位置 (documentation)。这很有效,但是,我还需要将返回的结果限制在一个国家/地区。
我为此使用“区域”字段,但它不会将结果限制在某个国家/地区,只会使它们产生偏见。我尝试使用“componentRestrictions”字段将结果限制在一个国家/地区。这很有效,但是,我最初设置的位置偏差(使用“边界”字段)似乎停止工作(或者至少现在工作方式不同)。
关于如何在这里实现我的目标有什么想法吗?
示例
我正在发送“35 bastion st.”的地理编码器请求。区域设置为 CA(加拿大),边界设置为加拿大不列颠哥伦比亚省温哥华周围 2.5 度。可以出现两个搜索结果:一个在加拿大安大略省多伦多,另一个在加拿大不列颠哥伦比亚省纳奈莫。我希望 Nanaimo 会出现在这种情况下,因为它的位置更近,而且确实如此。关联: https://maps.googleapis.com/maps/api/geocode/json?address=35%20bastion%20st.®ion=CA&bounds=46.7827,-125.6207|51.7827,-120.620&key=AIzaSyD3y1Mk-vZjfgqg1GB_dOWMDo004oY8xus
现在,如果我有相同的请求但应用了国家过滤器,我希望返回相同的结果,但事实并非如此。关联: https://maps.googleapis.com/maps/api/geocode/json?address=35%20bastion%20st.®ion=CA&bounds=46.7827,-125.6207|51.7827,-120,%20-122.1207&components=country:CA&key=AIzaSyD3y1Mk-vZjfgqg1GB_dOWMDo004oY8xus
编辑:
最佳答案
根据 Google 的说法,这不是错误(参见此处:https://issuetracker.google.com/issues/123557217)。
According to our engineers, this is working as intended.
The reason being that the country component will take priority when using the two parameters, as the use-cases of the two are entirely different.
Moreover, "35 Bastion st" is very ambiguous and it should be searched using Autocomplete where viewports/bounds can influence the results better.
关于javascript - 将 Google Maps API v3 搜索结果限制在某个国家/地区,同时偏向某个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54351816/