Last active
February 21, 2018 07:41
-
-
Save zainaali/9e83e66cff93c6476dbe3794aedfa3f7 to your computer and use it in GitHub Desktop.
Extract city 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 city from autocomplete address api | |
var city; | |
for(var a = 0; a < place.address_components.length; a += 1) { | |
var addressObj = place.address_components[a]; | |
for(var b = 0; b < addressObj.types.length; b += 1) { | |
if (addressObj.types[b] === 'locality') { | |
city = addressObj.long_name; // confirm that this is the country name | |
//console.log(addressObj.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