We can find the place name using google geocoder by giving the Latitude and Longitude.
For example we want to get the place name of the latitude: '17.434545' and longitude: '82.124575' we need to pass this values to the google api to get the place details.
Following code explains how to work with that.
function getPlaceName($latitude, $longitude)
{
//This below statement is used to send the data to google maps api and get the place
name in different formats. we need to convert it as required.
$geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng='
.$latitude.','.$longitude.'&sensor=false');
$output= json_decode($geocode);
//Here "formatted_address" is used to display the address in a user friendly format.
echo $output->results[0]->formatted_address;
}
We can use this function in PHP. when we execute the above method the following output will be displayed.
call the function as
<?php getPlaceName(17.434545, 82.124575); ?>
Output : Andhra Pradesh 533436, India
Thank you.
Thanks it's working fine
ReplyDeleteJust to clarify some point, your code is returning location name NOT place name , and there are differences between them , do get place name you have to use place API or Library :
ReplyDeletehttps://developers.google.com/maps/documentation/javascript/examples/place-details
Just Awesome trick. It works fine.Thanx a lot..
ReplyDeletewhat if just need city
ReplyDeleteThanks Helping finding a solution for it
ReplyDeleteSmall Business Management Software
ReplyDeleteExcellent, thanks!
ReplyDeletenice
ReplyDeleteThanks!!!!!!!!!!!!!!!!
ReplyDeleteFor sharing this code..i was tried its working and helpful for me.
Thanks very much for sharing this.
ReplyDeleteThank you very much and great work. It's working nicely... :)
ReplyDeleteLot of thanks
ReplyDeletethank brother
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteNice article, i am using this method in my webstie https://www.openacessjournal.com
ReplyDeleteThanks
Thank you.
ReplyDelete