首页 > 解决方案 > 获取数组 OpenStreetMap API 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['features'][0]['type']['geometry']['coordinates'];

但是,它失败了。我只是收到错误消息。

警告:第 12 行 C:\xampp\htdocs\mios\open\lokasi.php 中的非法字符串偏移“几何”警告:C:\xampp\htdocs\mios\open\lokasi.php 中的非法字符串偏移“坐标”线 12 F

如果我在这里打印 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 )

标签: phpjsonapi

解决方案


推荐阅读