跳轉至內容

XQuery/Flickr GoogleEarth

源自 Wikibooks,面向開放世界的開放書籍

對經過地理編碼的 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>
華夏公益教科書