javascript - 谷歌地点搜索位置偏差

标签 javascript google-maps google-maps-api-3 geolocation

我正在使用 Google 地方信息搜索,并且希望在海湾合作委员会国家(阿联酋、沙特阿拉伯、阿曼、科威特和巴林)上进行“位置偏差”。

我想实现以下目标 https://developers.google.com/maps/documentation/places/autocomplete#location_biasing

我想在文本框中提供 Google 地方信息搜索,而用户只能看到来自阿联酋、沙特阿拉伯、阿曼、科威特和巴林这些国家/地区的结果?

谢谢


我可以使用“componentRestrictions”参数在一个国家/地区进行“位置偏差”,如下面的代码片段所示

var mapOptions = {
          //bounds : defaultBounds,  
          center: new google.maps.LatLng(25.2644444, 55.31166669999993),
          zoom: 13,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        map = new google.maps.Map(document.getElementById('map_canvas'),
          mapOptions);

        var input = document.getElementById('searchTextField');        
        var InputOptions = {
            types: ['(cities)'],
            **componentRestrictions: { country: 'AE' } // I want multiple counteries here**
        };                
        var autocomplete = new google.maps.places.Autocomplete(input, InputOptions);

但我希望在上面提到的多个国家上进行位置偏差。

最佳答案

自 2017 年 1 月起,您现在可以在地点自动填充中为多个国家/地区创建过滤器。

You can now restrict Autocomplete predictions to only surface from multiple countries. You can do this by specifying up to 5 countries in the componentRestrictions field of the AutocompleteOptions.

https://developers.google.com/maps/documentation/javascript/releases

https://developers.google.com/maps/documentation/javascript/3.exp/reference#ComponentRestrictions

关于javascript - 谷歌地点搜索位置偏差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10886651/

相关文章:

javascript - 如何从谷歌地图标记数组中找出点击了哪个标记

javascript - Kineticjs - 鼠标悬停不准确

javascript - 强制循环等待两个函数依次运行

javascript - 如何将多段线绑定(bind)到可拖动标记

ios - 默认手势事件在谷歌地图中不起作用

android - 如何处理super.onCreate中的异常?

javascript - jQuery UI 可拖动超出事件顺序

javascript - 在 HTML 链接中使用 onClick 传递多个值

javascript - 尝试使用 GeoJSON 在谷歌地图上绘制标记

javascript - 覆盖图像覆盖自定义 Google map 网络中的标记