If we have latitude and longitude with us and we need to get location name out of that from google api then we need to do the following code;
public function findlocation($lat,$long){
$url_data = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.$lat.','.$long.'&sensor=true';
$get = file_get_contents($url_data);
$geoData = json_decode($get);
$status = $geoData->status;
if($status=="OK"){
$location=$geoData->results[0]->formatted_address;
}else
{
echo json_encode(array('status'=>'error','message'=>'Unable to get location out of given latitude and longitude')); die;
}
return $location;
}
This is how we could get the location of user from latitude and longitude
0 Comment(s)