Created
April 29, 2020 13:36
-
-
Save jrdn91/cdc8e9028b0706d34e7323955101665d to your computer and use it in GitHub Desktop.
Extract Google Places Data
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
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 "" | |
} |
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
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