In my previous post I explained how to get longitude and latitude from the address given, now in this post i will change few things and we will get address by giving longitude and latitude.
In the same way what we did in previous post, we use same Google API and PHP cURL.
Here i will explain only with cURl and not with file_get_contents.
$url="http://maps.google.com/maps/api/geocode/json?latlng=12.9715987,77.5945627&sensor=false";
i.e, in URL am giving latitude , longitude instead of Address.
$url="http://maps.google.com/maps/api/geocode/json?latlng=".$latitude.",".$longitude."&sensor=false";
Complete Code
$lat="12.9715987"; $lan="77.5945627"; $latlng=$lat.','.$lan; $latlng=urlencode($latlng); $url="http://maps.google.com/maps/api/geocode/json?latlng=".$latlng."&sensor=false"; $ch=curl_init();//initiating curl curl_setopt($ch,CURLOPT_URL,$url);// CLLING THE URL curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_PROXYPORT,3128); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0); $response=curl_exec($ch); $response=json_decode($response ); $places=$response->results[0]->formatted_address; echo $place;