I have a PHP page containing the following code to get latitude and longitude from a user input postal code.
But when I tried to echo the latitude and longitude, nothing is shown.
<?php
function getLnt($zip){
$url = "http://maps.googleapis.com/maps/api/geocode/json?address=".urlencode($zip)."&sensor=false";
$result_string = file_get_contents($url);
$result = json_decode($result_string, true);
return $result['results'][0]['geometry']['location'];
}
getLnt("750341");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<?php
$val = getLnt('90001');
echo "Latitude: ".$val['lat']."<br>";
echo "Longitude: ".$val['lng']."<br>";
?>
</body>
</html>
var_dump($val)?{ "results" : [], "status" : "ZERO_RESULTS" }. So if google returns nothing I think we can't manipulate it.Latitude: 33.9697897 Longitude: -118.2468148as output.var_dump($result_string);right after,$result_string = file_get_contents($url);what does it show ?