Created
March 14, 2014 20:50
-
-
Save aaronpeterson/9556592 to your computer and use it in GitHub Desktop.
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
/** | |
* This hasn't been unit tested. It also depends on address_component.types[0] | |
* being the primary type of interest i.e. not something like "political"... | |
*/ | |
function convertAddressComponents(addrComponents) { | |
var address = {}; | |
var typeMap = { | |
street_number: "streetNumber", | |
route: "streetName", | |
locality: "city", | |
administrative_area_level_2: "county", | |
administrative_area_level_1: "state", | |
country: "country", | |
postal_code: "postalCode" | |
}; | |
for (var i = 0; i < addrComponents.length; i++) { | |
var c = addrComponents[i]; | |
if (c.types[0] && typeMap[c.types[0]] && c.short_name) { | |
address[typeMap[c.types[0]]] = c.short_name; | |
} | |
} | |
return address; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment