I am trying to get google address from longitude and latitude. I tried it but not working
<?php
$sql_query = "SELECT * FROM `user_History` where uid = '$id'";
$stmt = $dbh->query($sql_query);
$i = 1;
while($row = $stmt->fetch( PDO::FETCH_ASSOC))
{
extract($row);
?>
<td><?php echo getaddress($row['lat'],$row['lon']); ?></td>
<?php } ?>
My function is:
<?php
function getaddress($lat,$lng)
{
$url = 'http://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 "no";
}
}
?>
And my google map api key is here:
<script src="http://maps.googleapis.com/maps/api/js?key=mykey1776135765176371&callback=initMap" type="text/javascript"></script>
It is not working. Returns no