Skip to content

Instantly share code, notes, and snippets.

@zainaali
Last active February 21, 2018 07:42
Show Gist options
  • Save zainaali/9e2b2a22bb035266dbc9e8347f4d4ac2 to your computer and use it in GitHub Desktop.
Save zainaali/9e2b2a22bb035266dbc9e8347f4d4ac2 to your computer and use it in GitHub Desktop.
Extract country from google autocomplete address api
autocomplete.addListener('place_changed', function() {
var place = autocomplete.getPlace();
//Extract country from autocomplete address api
var country;
for(var c = 0; c < place.address_components.length; c += 1) {
var locality = place.address_components[c];
for(var d = 0; d < locality.types.length; d += 1) {
if (locality.types[d] === 'country') {
country = locality.long_name; // confirm that this is the country name
}
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment