嗨,我的作业中收到以下错误,我不知道第21行的问题是什么问题isildata.php:
$dataJson = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=".$from."&destinations=".$to."&key=%20AIzaSyCWpwVwu1hO6TJW1H8x_zlhrLfbSbQ2r3o");
$data = json_decode($dataJson,true);
$nilaiJarak = $data['rows'][0]['elements'][0]['distance']['text'];
$time=$data['rows'][0]['elements'][0]['duration']['text'];
您必须检查您的请求是否正常
$dataJson = file_get_contents("https://maps.googleapis.com/maps/api/distancematrix/json?units=metric&origins=".$from."&destinations=".$to."&key=%20AIzaSyCWpwVwu1hO6TJW1H8x_zlhrLfbSbQ2r3o");
$data = json_decode($dataJson,true);
if ($data['status'] !== "OK") {
// Error
echo $data['error_message'];
// Do something
} else {
$nilaiJarak = $data['rows'][0]['elements'][0]['distance']['text'];
$time=$data['rows'][0]['elements'][0]['duration']['text'];
}