1

我尝试在 PHP 中回显地址的提升。我正在使用 Google Elevation API -链接

我已经有了纬度和经度。以下链接:

https://maps.googleapis.com/maps/api/elevation/json?locations=40.7143528,-74.0059731&key=myapikey

将在 json 中产生这些结果:

{ "results" : [ { "elevation" : 9.774918556213379, "location" : { "lat" : 40.7143528, "lng" : -74.00597310000001 }, "resolution" : 19.08790397644043 } ], "status" : "OK" }

我怎样才能呼应海拔?就像是<?php echo 'elevation'; ?>

谢谢

4

2 回答 2

2

您可以通过将响应更改为 xml 格式来做到这一点,以使事情变得更容易:

https://maps.googleapis.com/maps/api/elevation/xml?locations=40.7143528,-74.0059731&key=yourKey 如果您的 php 代码支持,您可以从那里执行以下操作:

<?php
$response = file_get_contents('https://maps.googleapis.com/maps/api/elevation/xml?locations=40.7143528,-74.0059731&key=myapikey');
$results = new SimpleXMLElement($response);
echo $results->elevation;
?>
于 2018-02-05T14:20:44.527 回答
0

该线程很旧,但我找到了一种替代方法,可用于在没有谷歌和密钥的情况下进行海拔查询。链接: https ://api.opentopodata.org/v1/eudem25m?locations=51.875127,10.65432 给出以下结果:

{
  "results": [
    {
      "dataset": "eudem25m", 
      "elevation": 352.5389709472656, 
      "location": {
        "lat": 51.875127, 
        "lng": 10.65432
      }
    }
  ], 
  "status": "OK"
}

可以用 php 评估:

$json = json_decode($result, true);
$result = $json['results'][0]['elevation'];

注意:在循环中查询时,必须包含一个睡眠,例如sleep(2);

于 2021-11-19T09:14:25.943 回答