Warning: include_once(analyticstracking.php): failed to open stream: No such file or directory in /www/wwwroot/studentstutorial.com/php-gps/php-address-from-longitude-latitude.php on line 37

Warning: include_once(): Failed opening 'analyticstracking.php' for inclusion (include_path='.:') in /www/wwwroot/studentstutorial.com/php-gps/php-address-from-longitude-latitude.php on line 37


Ask Question

Menu

How to get address from latitude longitude in PHP


index.php

<!DOCTYPE html>
<html>
<body>
<form method="post" action="process.php">
Latitude:<br>
<input type="text" name="latitude">
<br>
Longitude:<br>
<input type="text" name="longitude">
<br>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>

process.php

<?php
function getaddress($lat,$lng)
{
$url = '//maps.googleapis.com/maps/api/geocode/json?latlng='.trim($lat).','.trim($lng).'&sensor=false';
$json = @file_get_contents($url);
$data=json_decode($json);
$status = $data->status;
if($status=="OK") return $data->results[0]->formatted_address;
else
return false;
}
$lat=$_POST['latitude'];
$lng=$_POST['longitude'];
$address= getaddress($lat,$lng);
if($address)
{
echo $address;
}
else
{
echo "Not found";
}
?>










Subscribe