我正在使用 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/