Get address from Latitude and Longitude Coordinates in php
Get Address from given Latitude and Longitude Coordinates using google map api called Reverse Geocoding. It is the process of converting geographic coordinates (Latitude and Longitude) into addresses. Here is a little php function to get address from latitude and longitude.
The Php Script
This will output Janakpuri District Center, Janakpuri, New Delhi, Delhi 110058, India
You may also want a reverse process like Getting latitude and longitude coordinates from given address.
The Php Script
<?php function getAddress($lat, $lon){ $url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=". $lat.",".$lon."&sensor=false"; $json = @file_get_contents($url); $data = json_decode($json); $status = $data->status; $address = ''; if($status == "OK"){ $address = $data->results[0]->formatted_address; } return $address; } # Call function echo getAddress("28.6292", "77.0805"); ?>
You may also want a reverse process like Getting latitude and longitude coordinates from given address.
Get address from Latitude and Longitude Coordinates in php
Reviewed by JS Pixels
on
September 26, 2012
Rating:
Thanks altab bhai..i appriciate ur work..keep it up..
ReplyDeleteSalman Ahmad
India
blog:http://salmanahmd.blogspot.in/
Nice script
ReplyDeleteGood script,keep it up...
ReplyDeleteNice work. Saved my a lot time. Thanks.
ReplyDeleteI think there is a bug in this code. When I try to export the address to Microsoft Excel the characters are all looking funny. I think the address has problem with font. Please fix the code to display better font for copying into Excel
ReplyDeleteThere is nothing to do with the fonts here. the output is a simple text. May be there is a problem with your browser font settings. I have tested the script again and its working fine.
DeleteThere is something wrong, when i enter the US co-ordinates it will show address of China can you help me ..
ReplyDeleteyou are entering wrong longitude. There is need of negative mark on Longitude for USA address
Deletethanks bro...
ReplyDeleteThanks...good material....
ReplyDeletei can't get all address of 8000 entries
ReplyDeleteNice script Thank Altaf..
ReplyDeleteC - Hexagon, Pandara Flats, India Gate, New Delhi, Delhi 110001, India
ReplyDeletethanku so much..easy way
ReplyDeleteReally it works...Thanx alot Altaf Hussain.
ReplyDeletevery nice script .. thnx for uploading this
ReplyDeletehi mate? its working very well apart from one thing. It brings building name or house number which i don't want to be. is there any way i can get only street name and postcode. thanks
ReplyDeletegood it works..
ReplyDeleteis there any daily limit
ReplyDelete