我想在 Google map 服务上使用自动完成边界。但不工作。
//----autocomplete start
var input = (document.getElementById('searchPlace'));
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(40.518, 29.215),
new google.maps.LatLng(41.242, 30.370));
var options = {
bounds:defaultBounds,
componentRestrictions: { country: 'XX'},};
var autocomplete = new google.maps.places.Autocomplete(input, options);
//----autocomplete end
当我键入文本框时,地址来自 XX 国家/地区。但我想限制在某个国家/地区的搜索。例如城市边界。但是其他地址超出了这个范围。不考虑边界。
最佳答案
问题是 LatLngBounds期待西南 Angular 和东北 Angular 。也称为左下角和右上角。
代替:
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(40.518, 29.215),
new google.maps.LatLng(41.242, 30.370));
应该是:
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(41.242, 29.215),
new google.maps.LatLng(40.518, 30.370));
关于javascript - 谷歌地图自动完成边界不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18910636/