-
-
Save ravivit9/4c358065444c134dc11bd3858a6b4d77 to your computer and use it in GitHub Desktop.
Get only city and state from Google Maps API Reverse Geocoder
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
_getCityState = function(resp){ | |
var res = ''; | |
if (resp.status == 'OK') { | |
if (resp.results[1]) { | |
var city=false,state=false; | |
for (var i = 0; i < resp.results.length; i++) { | |
if ((!city || !state) && resp.results[i].types[0] === "locality") { | |
city = resp.results[i].address_components[0].short_name, | |
state = resp.results[i].address_components[2].short_name; | |
res = city + ", " + state; | |
} | |
} | |
} | |
} | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment