Google Places autocomplete Australia-only restriction -


how restrict google places australia only?

here 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); 

from autocomplete documentation:

restrict search specific country

use componentrestrictions option restrict autocomplete search particular country. following code restricts results 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"></script>  <input id="searchtextfield" type="text" />


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -