Php 在flickr中附加两个方法

Php 在flickr中附加两个方法,php,flickr,Php,Flickr,我必须使用Flickr的两种方法来实现我想要的结果;photos.search方法返回照片id,而geo.getLocation方法返回每个照片id的long和lat值。 我能够成功地迭代搜索,以获得搜索区域内的每个照片id。我的问题是如何在geo.getLocation方法中迭代每个照片id,以获得它们的纬度和经度值 下面是返回每个照片id的php代码: <?php $url = ("http://api.flickr.com/services/rest/?method=flickr.

我必须使用Flickr的两种方法来实现我想要的结果;photos.search方法返回照片id,而geo.getLocation方法返回每个照片id的long和lat值。 我能够成功地迭代搜索,以获得搜索区域内的每个照片id。我的问题是如何在geo.getLocation方法中迭代每个照片id,以获得它们的纬度和经度值

下面是返回每个照片id的php代码:

<?php

$url = ("http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=ff8c4c178209865b1ac5ee3f2d492de0&lat=51.5424&lon=-0.1734&radius=2&page=1&text=flats");

$xml = simplexml_load_file($url);

foreach ($xml->photos->photo as $entry) {  
echo $entry->attributes()->id;
echo $entry->attributes()->owner;
echo $entry->attributes()->title; 
}

?>

Yemi

为什么不在迭代照片ID时获取每个位置,如中所示

<?php

$url = ("http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=ff8c4c178209865b1ac5ee3f2d492de0&lat=51.5424&lon=-0.1734&radius=2&page=1&text=flats");

$xml = simplexml_load_file($url);

foreach ($xml->photos->photo as $entry) {  
   echo $entry->attributes()->id;
   echo $entry->attributes()->owner;
   echo $entry->attributes()->title;
   $xmlloc = simplexml_load_file("http://api.flickr.com/services/rest/?method=flickr.photos.geo.getLocation&api_key=xxxx&photo_id=" . $entry->attributes()->id);
// process XML file
}

?>

我实现了您的编辑,它不断返回错误:致命错误:在第11行的C:\…\search.php中超过了60秒的最大执行时间。。第11行是编辑行,这是API的超时问题,而不是代码的问题。您正在下载多少张照片-可能是您已超过API限制。我将per_page参数解析为50以减小结果大小,并且它不再返回任何错误。我想你是对的,但是我如何回显返回的纬度和经度值呢?我已经将循环中的变量名更改为$xmlloc,因为$xml是用于控制循环的变量。试着打印$xmlloc->photo->location->attributes->latitude以及同样的经度。最后,请考虑一下这个问题的答案。当然,一旦事情解决了,我会马上去做的。谢谢
<?php

$url = ("http://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=ff8c4c178209865b1ac5ee3f2d492de0&lat=51.5424&lon=-0.1734&radius=2&page=1&text=flats");

$xml = simplexml_load_file($url);

foreach ($xml->photos->photo as $entry) {  
   echo $entry->attributes()->id;
   echo $entry->attributes()->owner;
   echo $entry->attributes()->title;
   $xmlloc = simplexml_load_file("http://api.flickr.com/services/rest/?method=flickr.photos.geo.getLocation&api_key=xxxx&photo_id=" . $entry->attributes()->id);
// process XML file
}

?>