Created
November 29, 2012 14:40
-
-
Save funkjedi/4169508 to your computer and use it in GitHub Desktop.
Geocode address
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
<?php | |
function geocode_address($address) { | |
$output = array('address' => $address); | |
$response = json_decode(file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=" . urlencode($address) . "&sensor=false")); | |
switch ($output['status'] = $response->status) { | |
case 'OK': | |
$output['latitude'] = $response->results[0]->geometry->location->lat; | |
$output['longitude'] = $response->results[0]->geometry->location->lng; | |
$output['location_type'] = $response->results[0]->geometry->location_type; | |
break; | |
case 'ZERO_RESULTS': | |
case 'OVER_QUERY_LIMIT': | |
case 'REQUEST_DENIED': | |
case 'INVALID_REQUEST': | |
default: | |
error_log("Geolocation for '$address' failed with a status of %status."); | |
} | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment