Skip to content

Instantly share code, notes, and snippets.

Created July 14, 2013 16:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/5994903 to your computer and use it in GitHub Desktop.
Save anonymous/5994903 to your computer and use it in GitHub Desktop.
Geodecode position
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