我正在尝试返回限于区域类型的自动填充结果-
(区域)类型集合指示位置服务返回任何符合以下类型的结果:-地点-次地区- 邮政编码-国家-Administrative_area_level_1-Administrative_area_level_2
[https://developers.google.com/places/web-service/autocomplete][1]
但也锁定在欧盟范围内的严格限制。当我使用类型(城市)时,相同的代码有效。当我将类型更改为区域时,它会落下严格界限。地区是否与严格限制不兼容?我想念一些愚蠢的东西吗?同时删除该区域:'EU'参数无济于事。
function setup_autocomplete(){
//console.log( 'setting up autocomplete' );
//setbounds around EU
var circle = new google.maps.Circle({ center: new google.maps.LatLng( 54.0000, -4.0000 ), radius: 60000 });
var input = document.getElementById('home-carousel-location-input') || false,
options = {
region:'EU',
types: ['(regions)'],
bounds: circle.getBounds(),
strictbounds: true
}, autocomplete;
if( input ){
autocomplete = new google.maps.places.Autocomplete(input, options);
}
}
由于您正在使用不支持的region:
参数,因此您的“地方信息自动完成”实现似乎不太正确。这是可以在自动完成对象上设置的supported options的列表。
您可以删除region:
参数。您可以使用strictbounds:
和bounds:
参数设置区域限制。
autocomplete.setOptions({
strictBounds: true,
bounds: circle.getBounds(),
types: ['(regions)']
});
您可以尝试示例jsbin演示here。
在演示中,我将fillColor:
设置为圆形以可视化半径,并添加了矩形,同时还添加了fillColor:
以可视化严格限制。地方信息自动填充服务将返回范围内与(regions)
type匹配的所有结果。