Skip to content

Instantly share code, notes, and snippets.

@jamesholcomb
Created April 22, 2017 16:57
Show Gist options
  • Save jamesholcomb/3ba715bcae77d5b8b731c7f21c9adca2 to your computer and use it in GitHub Desktop.
Save jamesholcomb/3ba715bcae77d5b8b731c7f21c9adca2 to your computer and use it in GitHub Desktop.
Google Maps geocode address components to object using lodash
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