Hello
I'm trying to write a script that takes lat/long values, and returns an address. I came across a few tutorials and my code is as follows:
<?php
$lat=37.3568;
$lng=-122.085;
$peoplecount=5;
$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"){
$address = $data->results[0]->formatted_address;
}else{
$address='Could not determine address';
}
echo $address;
?>
I get the message:
PHP Notice: Trying to get property of non-object on line 13 (which is the line that says $status = $data ->status
On attempting to access the url directly in the browser, I get the following:
{
"results" : [],
"status" : "ZERO_RESULTS"
}
Is there something I'm doing wrong? Any advice would be appreciated.