Google maps 谷歌地图自动完成strictbounds参数不';行不通
我尝试使用Google Maps strictbounds参数将自动完成结果限制在特定区域。我目前的代码是: var autocomplete=new google.maps.places.autocomplete(空格地址,{types:['geocode'],strictbounds:{location:“-23.544085,-46.7125434”,半径:“12000”},语言:“pt BR”}) 虽然它不会破坏我的应用程序,但它也不会将结果限制在所选区域。或者,我使用了下面的国家限制,但客户不喜欢 以下是目前正在使用的完整代码:Google maps 谷歌地图自动完成strictbounds参数不';行不通,google-maps,autocomplete,Google Maps,Autocomplete,我尝试使用Google Maps strictbounds参数将自动完成结果限制在特定区域。我目前的代码是: var autocomplete=new google.maps.places.autocomplete(空格地址,{types:['geocode'],strictbounds:{location:“-23.544085,-46.7125434”,半径:“12000”},语言:“pt BR”}) 虽然它不会破坏我的应用程序,但它也不会将结果限制在所选区域。或者,我使用了下面的国家限制,
document.addEventListener("DOMContentLoaded", function() {
var spaceAddress = document.getElementById('space_address');
if (spaceAddress) {
var autocomplete = new google.maps.places.Autocomplete(spaceAddress, { types: [ 'geocode' ], strictbounds: {location: "-23.544085,-46.7125434", radius: "12000"}, language: "pt-BR" });
google.maps.event.addDomListener(spaceAddress, 'keydown', function(e) {
if (e.key === "Enter") {
e.preventDefault();
const spaceAddress = document.getElementById('space_address').value;
if (spaceAddress != '' && spaceAddress != null) {
codeAddress(spaceAddress);
}
}
});
}
有人能告诉我吗 首先需要创建一个google.maps.Circle类,然后使用该对象通过getBounds()获取边界。如前所述,strictbounds是一个布尔值
strictbounds
参数接受布尔值。请看中的示例。另一个示例
var circle = new google.maps.Circle({ center: new google.maps.LatLng(-23.544085, -46.7125434), radius: 12000 })
var autocomplete = new google.maps.places.Autocomplete(spaceAddress, { types: [ 'geocode' ], bounds: circle.getBounds(), strictbounds: true });