Conversion of geo-coordinates into address is known as Reverse Geocoding. In this script we are using Google map API because it’s free, fast and no API key required.
Rate Limit of Google reveres Geocoding is 2500 API calls per IP per day.
PHP function for Reveres Geocoding
<? function getaddress($lat,$lng) { $url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($lat).','.trim($lng).'&sensor=false'; $json = @file_get_contents($url); $data=json_decode($json); $status = $data->status; if($status=="OK") return $data->results[0]->formatted_address; else return false; } ?>
Pass latitude and longitude in getaddress() function. It will return address string on success otherwise return boolean false.
Example
<? $lat= 26.754347; //latitude $lng= 81.001640; //longitude $address= getaddress($lat,$lng); if($address) { echo $address; } else { echo "Not found"; } ?>
Very nice and simple code. thanks a lot
Hello Aditya,
The api was working properly but now it is returning a wrong address for a given latitue and logitude
Nice tutorial . Thanks for sharing with us .
But I faced a problem , sometimes when I run your code , address isn’t available for the same Latitude and longitude I used before and got address by same code.
Any solution ?
Thanks in Advance again .
How to get specific continent for lat and long
hi
thank you very much
how to set locate farsi?
and get me farsi language address
very nice tutorial
It not work for me online but work good on a localhost
how can i solve this ?