Created
July 14, 2013 16:49
-
-
Save anonymous/5994903 to your computer and use it in GitHub Desktop.
Geodecode position
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
function reverse_geocode($lat,$lng) { | |
$url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$lng&sensor=false&language=de"; | |
// echo $url; | |
$result = file_get_contents("$url"); | |
$json = json_decode($result); | |
foreach ($json->results as $result) { | |
foreach($result->address_components as $addressPart) { | |
//print_r($addressPart); | |
if((in_array('locality', $addressPart->types)) && (in_array('political', $addressPart->types))) { | |
$city = $addressPart->long_name; | |
} | |
else if((in_array('administrative_area_level_1', $addressPart->types)) && (in_array('political', $addressPart->types))) { | |
$state = $addressPart->long_name; | |
} | |
else if((in_array('country', $addressPart->types)) && (in_array('political', $addressPart->types))) { | |
$country = $addressPart->long_name; | |
} | |
} | |
} | |
$location = $city; | |
$location .= ", "; | |
$location .= $state; | |
$location .= ", "; | |
$location .= $country; | |
return $location; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment