Google 地图海拔 API 未返回结果 (JSON/PHP)

Google Maps Elevation API Not Returning Results (JSON/PHP)

我正在尝试使用 Google 地图高程 API,但没有 return 任何结果。我使用的代码如下:

<?php
$results = file_get_contents("https://maps.googleapis.com/maps/api/elevation/json?locations=-37.8,144.815&key=[myAPIkey]&sensor=false");
//$results = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address=Paris,France&sensor=false&key=[myAPIkey]");
$json = json_decode($results, true);
echo ${results};
//print_r($json); ?>

评论部分使用的是对我有用的地理编码 API,但是一旦我将 $results 变量更改为高程 API 它就不会 return 任何结果全部。当我将 URL 放入浏览器时,我得到 results.I 已在控制台中启用 API 并且有一个有效的 API 键。

有没有人知道为什么这不起作用?

确保在您的 API 控制台上启用了 Elevation API 并且您的 浏览器应用程序密钥 Any referrer allowed 或者如果您使用 服务器应用程序密钥 Any IP allowed

否则尝试使用 cURL

$curlUrlRequest = 'https://maps.googleapis.com/maps/api/elevation/json?locations=-37.8,144.815&key=[myApiKey]&sensor=false';

$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $curlUrlRequest);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$response = curl_exec($ch);
var_dump($response);