Created
April 22, 2017 16:57
-
-
Save jamesholcomb/3ba715bcae77d5b8b731c7f21c9adca2 to your computer and use it in GitHub Desktop.
Google Maps geocode address components to object using lodash
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
import _ from 'lodash' | |
const json = { | |
results: [] //...use actual results from API | |
} | |
const result = _.chain(json.results[0].address_components) | |
.keyBy('types[0]') | |
.mapValues('short_name') | |
.value() | |
// add lat/lng and address | |
result.location = json.results[0].geometry.location | |
result.formatted_address = json.results[0].formatted_address // eslint-disable-line camelcase |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment