Skip to content

Instantly share code, notes, and snippets.

@ravivit9
Forked from dody87/citystategeo.js
Created February 12, 2020 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravivit9/4c358065444c134dc11bd3858a6b4d77 to your computer and use it in GitHub Desktop.
Save ravivit9/4c358065444c134dc11bd3858a6b4d77 to your computer and use it in GitHub Desktop.
Get only city and state from Google Maps API Reverse Geocoder
_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