Skip to content

Instantly share code, notes, and snippets.

@charltoons
Created November 6, 2012 02:52
Show Gist options
  • Save charltoons/4022260 to your computer and use it in GitHub Desktop.
Save charltoons/4022260 to your computer and use it in GitHub Desktop.
Parses a Google Javascript API place object into a usable form
//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