当用户开始输入城市时,autosuggest 只会建议佛罗里达州坦帕市(或其他任何地方)50 英里以内的城市
var southWest = new google.maps.LatLng( 28.3914,-81.936035 );
var northEast = new google.maps.LatLng( 28.3914,-81.936035 );
var hyderabadBounds = new google.maps.LatLngBounds( southWest, northEast );
var options = {
bounds: hyderabadBounds,
types: ['geocode'],
componentRestrictions: { country: 'us' }
};
var input1 = document.getElementById('search_header');
var autocomplete = new google.maps.places.Autocomplete(input1,options);
最佳答案
您对海得拉巴边界的东北和西南使用相同的 LatLng,请使用包含所需区域的 LatLngBounds 对象,例如:
bounds: new google.maps.Circle({center:new google.maps.LatLng( 28.3914,-81.936035 ),
radius:50000}).getBounds()
注意:不能保证 Automplete 将结果限制在给定范围内
关于google-maps - google maps api v3 仅针对所选城市自动完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18873164/