This is a quick tutorial. In this tutorial, If you are looking to find address with latitude and longitude, then please keep your close attention in this as I am going to share how to find address with latitude and longitude using google maps API and PHP.
You can find the live demo of this tutorial below and also can download the complete scripts from given below link.
I have created a PHP function getaddress()
which will get the complete and formatted address from latitude and longitude with the help of google map API. See the below google map “http://maps.googleapis.com/maps/api/geocode/json?latlng=30.7333,76.7794&sensor=false”. Create an index.php file and copy paste below code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | < ?php //function to get address from lat long 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; } } ?> |
Lets use the above PHP function getaddress()
in your file. Copy below code to use in index.php file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | < ?php $lat= 30.7333; //latitude $lng= 76.7794; //longitude $address= getaddress($lat,$lng); if($address) { echo $address; } else { echo "Not found"; } ?> |
Hope this tutorial help you but If you still need any help to use above code, then feel free to add your comments in below comment section. I will be happy to answer your queries. Enjoy this tutorial, do you like & share this article with your friends, and don’t forget to follow us on Facebook and Twitter to be the first to learn the next great thing from Frewebmentor.
If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.
Article Tags: find address by latitude and longitude, find address from latitude and longitude coordinates, find address with longitude and latitude, find latitude and longitude of address, find latitude and longitude of an address, get address from latitude and longitude, gps coordinates converter to address, longitude or latitude