我通过以下链接查看示例 https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete?csw=1
我尝试了这个例子但是没有得到预期的输出地址超出了我提到的范围,下面我已经添加了我的自动完成代码请告诉我我出错了
var center22 = new google.maps.LatLng({ lat: 51.448386, lng: -0.199501 });
service = new google.maps.places.AutocompleteService();
service.getPlacePredictions({
input: query, location: center22, radius: 50000, strictbounds: true, componentRestrictions: { country: 'GB' }
}, function (predictions, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
dfd.resolve([]);
}
dfd.resolve(predictions);
return dfd.promise
}
});
答案 0 :(得分:1)
尚未为AutocompleteService实施严格边界。目前,您只能将结果偏向某个区域,但不限制。
https://developers.google.com/maps/documentation/javascript/reference#AutocompletionRequest
公共问题跟踪器中有一项功能请求:
https://issuetracker.google.com/issues/36219203
随时为此功能提出请求,以表达您的兴趣并订阅通知。
答案 1 :(得分:0)
你可以使用缩放。 初始化地图时可以设置缩放大小。
var map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -33.8688, lng: 151.2195},
zoom: 13
});
map.setZoom(12);