从GeoJSON OpenStreetMap获取数据

时间:2018-12-19 13:14:35

标签: php json

我试图从Json获取数据。这是我的脚本:

$jsonurl = "http://photon.komoot.de/api/?q=kemang+timur+jakarta&limit=1";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json, true);

echo $json_output[0]['city'];

但是,我无法获取城市数据。

这是Json的输出:

Array ( [features] => Array ( [0] => Array ( [geometry] => Array ( [coordinates] => Array ( [0] => 106.8230188 [1] => -6.2631289 ) [type] => Point ) [type] => Feature [properties] => Array ( [osm_id] => 31779962 [osm_type] => W [extent] => Array ( [0] => 106.8220505 [1] => -6.2624677 [2] => 106.823754 [3] => -6.263854 ) [country] => Indonesia [osm_key] => highway [city] => Jakarta Special Capital Region [osm_value] => residential [postcode] => 12730 [name] => Jalan Kemang Timur VI ) ) ) [type] => FeatureCollection )  

更新:

我使用它并且可以工作:

$jsonurl = "http://photon.komoot.de/api/?q=kemang+timur+jakarta&limit=1";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json, true);

echo $json_output['features'][0]['properties']['name'];

但是,如果我想获得协调,可以使用以下命令进行编辑:

$jsonurl = "http://photon.komoot.de/api/?q=kemang+timur+jakarta&limit=1";
$json = file_get_contents($jsonurl,0,null,null);
$json_output = json_decode($json, true);

echo $json_output['features'][0]['geometry']['coordinates'];

不起作用

0 个答案:

没有答案