可以设置我想在立交桥中获得的字段 api&

It is possible to set fields which i want to get in overpass api&

例如。我想获取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"
  }
}

我只想获取经度和纬度字段,这可能吗?

<?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);

首先使用json_decode解析响应体:

$parsed_data = json_decode($data);

然后您可以像这样访问各个字段:

$lat = $parsed_data->lat;
$lon = $parsed_data->lon;

您可以使用 skeleton print mode (out skel) 省略所有标签,因此稍微短一些。所以你的请求应该变成:[out:json];node['building']({$y1},{$x1},{$y2},{$x2});out skel;

目前 csv output mode ([out:csv]) 是您可以 select 显示字段的唯一模式。