Created
November 6, 2012 02:52
-
-
Save charltoons/4022260 to your computer and use it in GitHub Desktop.
Parses a Google Javascript API place object into a usable form
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
//change google address into something we can use | |
function parseAddress(addr){ | |
var newAddr = {}; | |
for (var i=0; i<addr.length; i++){ | |
switch (addr[i].types[0]){ | |
case "street_number": | |
newAddr.street_number = addr[i].long_name; | |
break; | |
case "route": | |
newAddr.street_name = addr[i].long_name; | |
break; | |
case "locality": | |
newAddr.city = addr[i].long_name; | |
break; | |
case "administrative_area_level_1": | |
newAddr.state = addr[i].long_name; | |
break; | |
case "postal_code": | |
newAddr.zip = addr[i].long_name; | |
break; | |
default: | |
break; | |
} | |
} | |
return newAddr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment