[英]Overpass API and json output in PHP
我正在使用立交桥Turbo在地图上显示信息。 我的部分代码(我使用PHP)如下:
//overpass query
$overpass = 'http://overpass-api.de/api/interpreter?data=[out:json];area(3600046663)->.searchArea;(node["amenity"="drinking_water"](area.searchArea););out;';
// collecting results in JSON format
$html = file_get_contents($overpass);
$jsonout = json_decode($html);
// this line just checks what the query would give as output
var_dump($jsonout);
JSON格式的查询结果( var_dump
显示的结果)如下所示:
version: 0.6
generator: "Overpass API"
osm3s:
timestamp_osm_base: "2017-11-03T06:25:02Z"
timestamp_areas_base: "2017-11-03T05:45:02Z"
copyright: "The data included in this document is from www.openstreetmap.org. The data is made available under ODbL."
elements:
0:
type: "node"
id: 254917402
lat: 46.0672187
lon: 11.1379545
tags:
amenity: "drinking_water"
1:
type: "node"
id: 257481472
lat: 46.0687113
lon: 11.1201097
tags:
amenity: "drinking_water"
等等。
您可以自己查看它,在浏览器中复制/粘贴查询URL: http : //overpass-api.de/api/interpreter?data=[out : json];area(3600046663)-%3E.searchArea;(node [%22amenity%22 =%22drinking_water%22](area.searchArea);); out;
如您所见,上面数组中的每个element
都有纬度和经度信息。 我需要那些在地图上显示标记。
我不能够隔离lat
和lon
从阵列中的每个元素的信息 。 我怎样才能做到这一点?
干得好:
<?php
// overpass query
$overpass = 'http://overpass-api.de/api/interpreter?data=[out:json];area(3600046663)->.searchArea;(node["amenity"="drinking_water"](area.searchArea););out;';
// collecting results in JSON format
$html = file_get_contents($overpass);
$result = json_decode($html, true); // "true" to get PHP array instead of an object
// elements key contains the array of all required elements
$data = $result['elements'];
foreach($data as $key => $row) {
// latitude
$lat = $row['lat'];
// longitude
$lng = $row['lon'];
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.