SimpleXML返回空数组 [英] SimpleXML returns empty arrays
本文介绍了SimpleXML返回空数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过Google Maps API和PHP(SimpleXML)获取城市的经纬度。
我尝试这样做:
$ xml = simplexml_load_file(http://maps.googleapis.com/maps/api/geocode/xml?address =布鲁塞尔,比利时&安培;传感器=假);
$ lat = $ xml-> xpath(lat);
print_r($ lat);
但是每次都返回一个空数组。
我是否缺少某些东西?
任何帮助都是非常值得赞赏的。
解决方案
><?php
$ xml = simplexml_load_file(http://maps.googleapis.com/maps/api/geocode/xml?address=Brussels,Belgium&sensor=false);
$ lat = $ xml-> xpath(/ GeocodeResponse / result / geometry / location / lat);
print_r($ lat);
?>
对于所有 lat
出现次数,指定路径 // lat
。
I'm trying to get the latitude and longitude of a city with the Google Maps API and through PHP (SimpleXML).
I try to do it like this:
$xml = simplexml_load_file("http://maps.googleapis.com/maps/api/geocode/xml?address=Brussels,Belgium&sensor=false");
$lat= $xml->xpath("lat");
print_r($lat);
But this returns an empty array every time. Am I missing something?
Any help is much appreciated.
解决方案
To search for a particular lat
do this:
<?php
$xml = simplexml_load_file("http://maps.googleapis.com/maps/api/geocode/xml?address=Brussels,Belgium&sensor=false");
$lat= $xml->xpath("/GeocodeResponse/result/geometry/location/lat");
print_r($lat);
?>
For all lat
occurrences specify the path of //lat
.
这篇关于SimpleXML返回空数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文