284 Part III — Google Map Hacks
‘/examples/ch14-02flickrproxy.pl?method= ;
flickr.photos.search&api_key=’ +
‘XXX’ + ‘&user_id=54256647@N00’ +
‘&tags=toronto,geotagged&tag_mode=all’,true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlsource = request.responseXML;
var photos = ;
xmlsource.documentElement.getElementsByTagName(“photo”);
for(i=0;i<photos.length;i++) {
var img = document.createElement(‘img’);
photoids.push(photos[i].getAttribute(‘id’));
}
getphotoinfo(0);
}
}
request.send(null);
}
Only the ID of the photo is required. You have found the photos you are looking for. To deter-
mine the geographical information, you have to get the specific information for each photo
to extract the geotagsand plot the photo location on the map. Unfortunately, this requires
sending one request per photo and then parsing another XML file for each photo to extract the
data required.
That operation of getting individual photo data is handled by the getphotoinfo()function.
Because you are sending multiple asynchronous HTTP transfers, you create a chain of requests,
starting with the first photo ID. Each getphotoinfo()call then calls the function again for
the next photo and so on. I’ve found this to be more reliable than calling getphotoinfo()
within a forloop.
Getting Individual Photo Data
The Flickr database stores a lot of information about each photo. The basic data returned
about a photo includes the photo ID and other data used for loading and locating the photo,
the photo dates, the tag information, and the URL of the photo’s page within the Flickr site.
You need to separately extract this information for each photo. From that, you can get the geo-
graphic data and then create a marker on the map where the photo was taken. You’ll also use an
XSL Transformation to convert the returned XML into an info window that displays the basic
photo data and a thumbnail of the photo without your map.
Getting Specific Photo Data
When you request the information for a single photo, you get a comparatively large XML doc-
ument returned that contains a wealth of information. The bulk of this will be converted by an
XSL Transformation into the InfoWindowfor each marker, but the tag information will be
used to determine the location of where the photo was taken.