I narrowed autocomplete to a region and to a bounds that cover only Australia, but I am still receving autocomplete with Chile and China and other country out of the selected area. Does anyone have a good solution to work this problem? I also can't change the styling off Google autocomplete, it is a self generated Div with style tag that overcomes my style to autocomplete DIV? I started to use Geocoder and Jquery autocomplete to filter the results but it doesn't work as well as Google Autocomplete the results are less than google maps autocomplete?
I call the Library like this:
Here is the code of creating the auto complete:
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(-47.5765257137462, 106.259765625),
new google.maps.LatLng(-9.6, 179.359375));
var options = {
bounds: defaultBounds,
types: ['geocode'],
offset: 5
};
var input = document.getElementById('store-locator-header');
var autocomplete = new google.maps.places.Autocomplete(input,options);
Currently, you can use componentRestrictions to filter by country. The country must be passed as as a two character, ISO 3166-1 Alpha-2 compatible country code. Save this answer.
Nowadays, you can restrict to a country with:
componentRestrictions: {country: 'us'},
When Adding Autocomplete with bounds
, results are biased towards, but not restricted to, Places contained within these bounds. This is the same as when using Viewport Biasing in the Geocoding API. I'm afraid I don't have a method to filter out those suggestions that fall outside of the bounds
.
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