Skip to content

Instantly share code, notes, and snippets.

@jrdn91
Created April 29, 2020 13:36
Show Gist options
  • Save jrdn91/cdc8e9028b0706d34e7323955101665d to your computer and use it in GitHub Desktop.
Save jrdn91/cdc8e9028b0706d34e7323955101665d to your computer and use it in GitHub Desktop.
Extract Google Places Data
export default (components, type, part = "long_name") => {
for (var i = 0; i < components.length; i++) {
for (var j = 0; j < components[i].types.length; j++) {
if (components[i].types[j] === type) return components[i][part]
}
}
return ""
}
import extractFromAddress from "utils/extractFromAddress"
const streetNumber = extractFromAddress(
results[0].address_components,
"street_number"
)
const route = extractFromAddress(
results[0].address_components,
"route"
)
const city = extractFromAddress(
results[0].address_components,
"locality"
)
const state = extractFromAddress(
results[0].address_components,
"administrative_area_level_1",
"short_name"
)
const zip = extractFromAddress(
results[0].address_components,
"postal_code"
)
const country = extractFromAddress(
results[0].address_components,
"country"
)
const place = {
street: `${streetNumber} ${route}`,
city,
state,
zip,
country
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment