我正试图找出一种使用SimpleXML从flickr api XML请求中提取纬度和经度的方法。
我尝试了以下SimpleXML php脚本:
<?php
$xml = simplexml_load_file("http://api.flickr.com/services/rest/?method=flickr.places.placesForTags&api_key=XXXX&place_type_id=7&tags=Defenders+of+Wildlife&format=rest&auth_token=XXXX-XXXX&api_sig=XXXX");
foreach ($xml->places->place as $item) {
print "<p>";
print $item->latitude;
print ","
print $item->longitude;
print "</p>";
print "<br>";
}
?>
以下是URL API请求的XML文档树:
<rsp stat="ok">
<places total="97">
<place place_id="Ayf3HfhQVrOfB2kB" woeid="1492513" latitude="-18.947" longitude="48.521" place_url="/Madagascar/Toamasina/Andasibe" place_type="locality" place_type_id="7" timezone="Indian/Antananarivo" woe_name="Andasibe" photo_count="63">Andasibe, Toamasina, Madagascar</place>
<place place_id="gTWfoV5WU7jJ3tE" woeid="712142" latitude="39.173" longitude="8.976" place_url="/Italy/Sardinia/Capoterra" place_type="locality" place_type_id="7" timezone="Europe/Rome" woe_name="Capoterra" photo_count="44">Capoterra, Sardinia, Italy</place>
</places>
</rsp>
关于我如何才能获得经度和纬度的任何建议?
感谢!!!
答案 0 :(得分:0)
访问数组之类的属性:
print $item['latitude'];
参见http://www.php.net/manual/en/simplexml.examples-basic.php,示例#5