Created
May 17, 2018 13:46
-
-
Save vitaliy-kravchenko-dev/a97b17603b183dc4a6713ecbbdd09988 to your computer and use it in GitHub Desktop.
Extract city and country from Google maps API response - geocoder.geocode()
This file contains 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
getCityCountry(results) { | |
const location: any = {}; | |
for (const component of results[0].address_components) { | |
if (component.types.includes('sublocality') || component.types.includes('locality')) { | |
location.city = component.long_name; | |
} else if (component.types.includes('administrative_area_level_1')) { | |
location.state = component.short_name; | |
} else if (component.types.includes('country')) { | |
location.country = component.long_name; | |
location.registered_country_iso_code = component.short_name; | |
} | |
} | |
return location; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment