【发布时间】:2012-07-07 11:18:33
【问题描述】:
如何在 php 中解析 JSON google maps JSON
我已经在xml中做了,但是坐标驱动方向不完整,因为我用JSON得到,我们如何在php中用JSON得到所有坐标驱动?
如果我们使用 xml
$xml = simplexml_load_file('http://maps.googleapis.com/maps/api/directions/xml?origin='.$origin.'&destination='.$dest.'&sensor=false');
$startlat = $xml->xpath("/DirectionsResponse/route/leg/step/start_location/lat");
$startlng = $xml->xpath("/DirectionsResponse/route/leg/step/start_location/lng");
$distanceeach = $xml->xpath("/DirectionsResponse/route/leg/step/distance/value");
$distance = $xml->xpath("/DirectionsResponse/route/leg/distance/value");
但是如何处理 json? 如果我们使用 xml,我希望我的变量 $startlat、$startlng 等包含相同的值
【问题讨论】:
标签: php xml json parsing google-maps