XQuery/Flickr GoogleEarth
外观
< XQuery
对经过地理编码的 Flickr 照片可以使用 GoogleEarth 叠加图。
[** 本服务器上尚未启用 API **]
Flickr Api 和 kml 转换的代码。$flickrKey 是我的 Flickr API 密钥(未显示)。
declare option exist:serialize "method=xhtml media-type=application/vnd.google-earth.kml+xml";
declare function local:callFlickr($method,$params){
doc(concat("http://api.flickr.com/services/rest/?method=",$method,"&api_key={$flickrKey}",
string-join($params,"&")))
};
let $username := request:request-parameter("username","")
let $tags := string-join(request:request-parameter("tags",""),",")
let $user := string(local:callFlickr("flickr.people.findByUsername",concat("username=",$username))//user/@id)
return
<Folder>
<name>Places for {$username} tagged {$tags}</name>
{ for $photo in local:callFlickr("flickr.photos.search",(concat("user_id=",$user),concat("tags=",$tags)))//photo
let $photo_id := string($photo/@id)
let $details := local:callFlickr("flickr.photos.getInfo",concat("photo_id=",$photo_id))//photo
where exists($details/location)
return
<Placemark>
<name>{string($details/title)}</name>
<description>
{let $url := string(local:callFlickr("flickr.photos.getSizes",concat("photo_id=",$photo_id))//size[@label="Small"]/@source)
return
util:serialize(<div> <a href="http://www.flickr.com/photos/{string($details/owner/@nsid)}/{$photo_id}"><img src="{$url}"/></a> </div>,())
}
<div>{string($details/description)}</div>
</description>
<Point>
<coordinates>{string($details/location/@longitude)},{string($details/location/@latitude)},0</coordinates>
</Point>
</Placemark>
}
</Folder>