Skip to content

Instantly share code, notes, and snippets.

/gist:5994903
Created Jul 14, 2013

Embed
What would you like to do?
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
You can’t perform that action at this time.