Google Maps Reverse Geocoding API in PHP
Google Maps Reverse Geocoding API is the tool (web-service), which converts the given geo-coordinates (latitude , longitude) in to human readable format address like in the illustration below
13.0810 & 80.2740 ————> Poonamallee High Road, Park Town, Chennai, Tamil Nadu, India
(Geo-coordinates) (Human Readable format address)
So Google Maps Reverse Geocoding API is a web service, which gives JSON or XML formatted output when you send input in right format Here is URL of the Google Maps Reverse Geocoding API web service.
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=true_or_false
where
latlang – Latitude & Langitude value of location on maps for which we need human readable address.
sensor (true) – Indicates geocode request from device with sensor.
(note : sensor parameter must be true or false in the url while requesting result)
http://maps.googleapis.com/maps/api/geocode/json?latlng=13.0810,80.2740&sensor=true
Sample JSon output for the given latlng value (13.0810,80.2740).
“formatted_address” : “Poonamallee High Road, Park Town, Chennai, Tamil Nadu, India”,
“geometry” : {
“bounds” : {
“northeast” : {
“lat” : 13.08159910,
“lng” : 80.27514250
},
“southwest” : {
“lat” : 13.08136550,
“lng” : 80.27338689999999
}
},
“location” : {
“lat” : 13.08149240,
“lng” : 80.27426340
},
“location_type” : “APPROXIMATE”,
“viewport” : {
“northeast” : {
“lat” : 13.08283128029150,
“lng” : 80.27561368029150
},
Now we are going get human readable format address for the given latitude and longitude co-ordinates using PHP.
Steps:
1. Getting user entered latitude and longitude co-ordinates.
2. Sending that url request with co-ordinates we got from user, to that Google Maps Reverse Geocode API.
3. Google Maps Reverse Geocode API provides JSON formatted string output, now converting that JSON formatted string into JSON object using json_decode() method.
4. Finally getting human readable address from the JSON output.
Here is the script to download
Here is sample script to convert given geo-coordinates into human readable format address using Google Maps Reverse geocode API.
<?php if(isset($_POST['latitude'])){ $lat=$_POST['latitude']; $long=$_POST['longitude']; $address=file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?latlng=$lat,$long&sensor=true"); $json_data=json_decode($address); $full_address=$json_data->results[0]->formatted_address; ?>
Know more about Google Maps Reverse Geocoding service...
Download Premium Only Scripts & 80+ Demo scripts Instantly at just 1.95 USD per month + 10% discount to all Exclusive Scripts
If you want any of my script need to be customized according to your business requirement,
Please feel free to contact me [at] muni2explore[at]gmail.com
Note: But it will be charged based on your customization requirement