XQuery/Flickr GoogleEarth

Flickr photos which are geo-coded can be used to generate a GoogleEarth overlay.

[** API not functional on this server yet **]

Select Photos

The code for the Flickr Api to kml transformation. $flickrKey is my Flickr API key (not shown).


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>