我正在尝试使用 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 key 。
有没有人知道为什么这不起作用?
最佳答案
确保在您的 API 控制台上Elevation API 已启用并且您的浏览器应用程序 key 具有允许的任何引用
,或者如果您使用服务器应用程序 key 允许任何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);
关于php - Google Maps Elevation API 不返回结果 (JSON/PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30498536/