在我使用Google Maps API v3的javascript代碼中,我嘗試設置自動完成功能的邊界,只要在輸入字段中輸入一個字母, HTML),相同的自動完成提示我可以在邊界區域找到地址,但是如果我鍵入超出邊界限制的城市名稱,我也會爲該城市和其他城市提供建議。有沒有辦法避免這種情況?我想只爲我的「界限」提供建議。谷歌地圖v3 - 限制功能可以工作的區域
下面是一段代碼:
init = function() {
var latlng = new google.maps.LatLng(40.635636, 17.942414);
var mapOptions = { zoom: 13, center: latlng, minZoom: 10, maxZoom: 16};
default_bounds = new google.maps.LatLngBounds();
default_bounds.extend(new google.maps.LatLng(40.635636-0.33, 17.942414-0.33));
default_bounds.extend(new google.maps.LatLng(40.635636+0.33, 17.942414+0.33));
console.log("Initialing map at: 40.635636, 17.942414");
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
originAutocomplete = new google.maps.places.Autocomplete(document.getElementsByName("origin")[0], {types: ['geocode']});
destinationAutocomplete = new google.maps.places.Autocomplete(document.getElementsByName("destination")[0], {types: ['geocode']});
originAutocomplete.setBounds(default_bounds);
destinationAutocomplete.setBounds(default_bounds);
}
圖像正確:(顯示在普利亞大區唯一的地方意大利南部) 不正確的圖像:(很多不同地區的演出場所)
這是不可能的,邊界屬性不是限制,它只是一個選擇在邊界內選擇結果的選項 –