I want to use autocomplete bounds on Google maps service. But not working.
//----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
When I type the textbox, the addresses are coming in XX country. But I wanna restrict the search in a region of country. For example a city bounds. But other addresses are coming out of this bounds. Bounds are not considered.
The problem is that LatLngBounds expects south-west and north-east corners. Also referred as bottom-left and top-right corners.
Instead of:
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(40.518, 29.215),
new google.maps.LatLng(41.242, 30.370));
It should be:
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(41.242, 29.215),
new google.maps.LatLng(40.518, 30.370));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With