Skip to content

Instantly share code, notes, and snippets.

@buralex
Forked from danasilver/citystategeo.js
Last active January 2, 2018 08:37
Show Gist options
  • Save buralex/f17bcbf7471b4d4de357dfe30f106e04 to your computer and use it in GitHub Desktop.
Save buralex/f17bcbf7471b4d4de357dfe30f106e04 to your computer and use it in GitHub Desktop.
Get only city and state from Google Maps API Reverse Geocoder
for (var ac = 0; ac < results[0].address_components.length; ac++) {
var component = results[0].address_components[ac];
switch(component.types[0]) {
case 'locality':
storableLocation.city = component.long_name;
break;
case 'administrative_area_level_1':
storableLocation.state = component.short_name;
break;
case 'country':
storableLocation.country = component.long_name;
storableLocation.registered_country_iso_code = component.short_name;
break;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment