例如。我想获取bbox中所有节点建筑物的坐标。
PHP
$queryBuildings="[out:json];node['building']({$y1},{$x1},{$y2},{$x2});out;";
$data = file_get_contents("http://overpass-api.de/api/interpreter?data={$queryBuildings}")
结果中的一个元素:
{
"type": "node",
"id": 29537155,
"lat": 54.6744568,
"lon": -2.1421066,
"tags": {
"building": "house",
"description": "Abandoned (2007). Associate with lead mine workings above it?",
"name": "Flushiemere House"
}
}

我想只获得lon和lat字段吗?
答案 0 :(得分:1)
您可以使用省略所有标记的skeleton print mode(out skel
),因此会略短。因此,您的请求应该变为:[out:json];node['building']({$y1},{$x1},{$y2},{$x2});out skel;
目前csv output mode([out:csv]
)是唯一可以选择要显示的字段的模式。
答案 1 :(得分:0)
<?php
$data = '{
"type": "node",
"id": 29537155,
"lat": 54.6744568,
"lon": -2.1421066,
"tags": {
"building": "house",
"description": "Abandoned (2007). Associate with lead mine workings above it?",
"name": "Flushiemere House"
}
}';
$test = json_decode($data);
var_dump($test->lon);
答案 2 :(得分:0)
首先使用json_decode来解析响应正文:
$parsed_data = json_decode($data);
然后您可以访问各个字段:
$lat = $parsed_data->lat;
$lon = $parsed_data->lon;