Created
October 15, 2010 14:33
-
-
Save mbmccormick/628268 to your computer and use it in GitHub Desktop.
Query Google Maps GeoCode API with zip code and return city and state.
This file contains hidden or 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
<?php | |
$zipcode = $_GET[zipcode]; | |
$url = "http://maps.googleapis.com/maps/api/geocode/xml?sensor=false&address=" . $zipcode; | |
$geocode = simplexml_load_file($url); | |
$city = $geocode->result->address_component[1]->long_name; | |
for ($i = 2; $i < 6; $i++) | |
{ | |
if ($geocode->result->address_component[$i]->type == "administrative_area_level_1") | |
{ | |
$state = $geocode->result->address_component[$i]->short_name; | |
break; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment