Last active
February 21, 2018 07:42
-
-
Save zainaali/9e2b2a22bb035266dbc9e8347f4d4ac2 to your computer and use it in GitHub Desktop.
Extract country from google autocomplete address api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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