我必须使用Flickr中的两种方法来实现我想要的结果; “photos.search方法”返回照片ID,而“geo.getLocation方法”返回每张照片ID的long和lat值。 我能够成功迭代搜索以获取搜索区域内的每张照片ID。我的问题是如何迭代“geo.getLocation方法”中的每个照片ID,以获得它们的纬度和经度值。
在下面找到我的PHP代码,它返回每张照片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;
}
?>
geo.getLocation方法的REST请求格式为:
http://api.flickr.com/services/rest/?method=flickr.photos.geo.getLocation&api_key=xxxx&photo_id=[value]
Yemi
答案 0 :(得分:0)
为什么不在迭代照片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
}
?>