Google Maps Elevation API未返回结果(JSON / PHP)

我正在尝试使用Google Maps Elevation API,但未返回任何结果.我正在使用的代码如下:

<?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变量更改为Elevation API,它根本不会返回任何结果.将URL放入浏览器后,我得到结果.我已在控制台中启用了API,并具有有效的API密钥.

有谁知道为什么这行不通?

解决方法:

确保在您的API控制台上启用了Elevation API,并且您的浏览器应用程序密钥具有允许的任何引荐来源网址,或者如果您使用服务器应用程序密钥,则允许任何IP

否则尝试使用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);

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...