我有一个包含以下代码的PHP页面,用于从用户输入的邮政编码获取纬度和经度。
但是当我尝试输出纬度和经度时,什么也没有显示。
但是当我尝试输出纬度和经度时,什么也没有显示。
<?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)
吗? - u_mulder{ "results" : [], "status" : "ZERO_RESULTS" }
。所以如果谷歌没有返回任何结果,我认为我们无法对其进行操作。 - Dhay纬度:33.9697897,经度:-118.2468148
。 - Pedro Lobito$result_string = file_get_contents($url);
之后立即执行var_dump($result_string);
,它显示了什么? - Pedro Lobito