How get an address from latitude and longitude by using google api

php

Posted on 06 Aug 15 by Vickey
  733



By using google api we can get latitude and longitude of a given location and we can also get the location details if we have latitude and longitude of that location.

With the help of below code you can get location details if you have latitude and longitude of a location

echo getAddressByLatLong('-4734774834','005347587');

public function getAddressByLatLong($loc_latitude='',loc_longitude='')
{
    $loc_latitude=trim($loc_latitude);
    $loc_longitude=trim($loc_longitude);
    $api_url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.$loc_latitude.','.$loc_longitude.'&sensor=false';
    
    $location_record = @file_get_contents($api_url);
    $location_data=json_decode($location_record);

    $location_status = $location_data->status;
    if($location_status=="OK")
        return $location_data->results[0]->formatted_address;
    else
        return false;
}

 


If this post help you reduce time to develop, you can help me to maintain this website :)
www.000webhost.com