I have a database with exact addresses (street, no, city, region/area, country). However, I was wondering if there was a way to use Google API to get the district of a city (e.g. "Manhattan") if we are in New York?
All the other information I have already in the database, so I would just need the district if there is one (of course this will be only in larger cities)...
UPDATE:
I found this function on http://www.techques.com/question/1-3151450/Google-geolocation-API---Use-longitude-and-latitude-to-get-address and tried to change formatted_address
to sublocality (even others like short_name etc.) but it does not return anything... any help would be highly appreciated! Thank you!!
function reverse_geocode($lat, $lon) {
$url = "http://maps.google.com/maps/api/geocode/json?latlng=$lat,$lon&sensor=false";
$data = json_decode(file_get_contents($url));
if (!isset($data->results[0]->formatted_address)){
return "unknown Place";
}
return $data->results[0]->formatted_address;
}
I came up with the following.
You can access the sublocality like this:
You'll find this information inside a geocode-request, when there exists a result with the
types
set toExample: 317 Madison Ave,New York City
Modification of the function above for easy access of the response-components: