Reputation: 97
How do I restrict Google Places to Australia only?
Here is the code I'm using:
function initialize() {
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input);
}
google.maps.event.addDomListener(window, 'load', initialize);
Upvotes: 3
Views: 5896
Reputation: 161384
From the autocomplete documentation:
Restrict the search to a specific country
Use the componentRestrictions option to restrict the autocomplete search to a particular country. The following code restricts the results to cities within France.
var input = document.getElementById('searchTextField');
var options = {
types: ['(cities)'],
componentRestrictions: {country: 'fr'}
};
autocomplete = new google.maps.places.Autocomplete(input, options);
For Australia use 'au':
function initialize() {
var options = {
componentRestrictions: {country: 'au'}
};
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
code snippet:
function initialize() {
var options = {
componentRestrictions: {country: 'au'}
};
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script>
<input id="searchTextField" type="text" />
Upvotes: 10
Reputation: 586
Just know that you can enter bogus addresses into Google places search
Just use 19320483920489230 Station Street for example (any suburb).
If you need an address checking service, there are far better solutions, Google places is quick and 'dirty', not quick and 'clean' data.
Upvotes: 0