Flickr Photo and Google Maps Mashup
My Flickr photo set mapped using the Google Maps API.
Javascript to retrieve the Flickr KML from a handler on this web server, create the
markers, load it onto the map and create a clickable list of photos:
$(document).ready(function() {
initialize();
$(window).unload(function() {
GUnload();
});
});
function toggleCode()
{
$("#codeEx").toggle("slow");
}
var map;
var geoXml;
var toggleState = 1;
var mapListHTML = "";
var gMarkers = [];
function initialize()
{
if (GBrowserIsCompatible())
{
$.get("FeedServer.ashx?url=http://api.flickr.com/services/feeds/geo/?id=34122602@N00&lang=en-us&format=kml_nl",
function(data) {
$("#map_list").empty();
$(data).find('entry').each(function() {
var $item = $(this);
var title = $item.find('title').text();
var lat = $item.find("geo\\:lat").text();
var lng = $item.find("geo\\:long").text();
var content = $item.find("content").text();
var point = new GLatLng(lat,lng);
var marker = createMarker(point, title , content)
map.addOverlay(marker);
});
$("#map_list").append("<h3>Photos</h3>" + mapListHTML);
});
map = new GMap2($("#map_canvas")[0]);
map.setCenter(new GLatLng(19.693225,-100.090423), 2);
map.addControl(new GLargeMapControl());
}
}
function createMarker(point,name,html)
{
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
gMarkers.push(marker);
mapListHTML += "<div style=\"margin-bottom:4px;\">";
mapListHTML += "<a href=\"javascript:photoItemClick(" + (gMarkers.length - 1) + ")\">" + name + "<\/a></div>";
return marker;
}
function photoItemClick(i) {
GEvent.trigger(gMarkers[i], "click");
}
The server-side code to expose the RSS feed (same as used elsewhere on this site):
<%@ WebHandler Language="C#" Class="FeedServer" %>
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Services;
using System.Xml.Linq;
public class FeedServer : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
string url = context.Request.QueryString["url"];
XDocument feedXML = XDocument.Load(url);
context.Response.ContentType = "text/xml";
context.Response.Write(feedXML.ToString());
}
}