Hack 38. Add Location to Weblogs and RSS Feeds

Here are two easy ways to add location tags to your weblog entries or RSS feed items.

Weblogs and RSS syndication are drastically changing the way people read, write, and experience the Web. As could be predicted, location figures heavily into many of the sort of things people like to blog about: vacations, sporting events, concerts, and so on. We'll examine two simple methods to add location tags to your weblog, using plug-ins for Movable Type and Radio Userland, but the same principles apply to any RSS feed.

First, let's have a closer look at geotagged RSS. RSS 1.0, 2.0 (http://blogs.law.harvard.edu/tech/rss), and Atom are extendable with XML namespaces. There are two commonly used namespaces to represent location: the RDF Interest Group Geo vocabulary (http://www.w3.org/2003/01/geo/) and the ICBM namespace (http://postneo.com/icbm/). The examples here will use RSS 2.0 with the RDFIG Geo vocabulary, but other combinations are possible. Here's what RSS2+Geo looks like:

Taqueria Vallartahttp://www.taqueria-vallarta.com
 
 This taqueria in Santa Cruz, CA is an excellent value. Get the
 Super Vegetarian with extra guacamole.
 
  36.9716 
  -122.0253 

That's all there is to it. Now, mapping applications that know how to speak RDFIG Geo will able to make use of this information when reading your blog feeds, while RSS readers and aggregators that don't will simply read the item as normal.

You'll note that the longitude given for Taqueria Vallarta is negative, because Santa Cruz, California, is west of the prime meridian. In general, most cartographic applications expect west longitude and south latitude to be given with negative values, unless otherwise specified.

 

4.5.1. Adding Location Tags to Movable Type

To publish RSS2+Geo with Movable Type, we'll build on Timothy Appnel's Meta plug-in (http://mt-plugins.org/archives/entry/meta.php). It's described as "a simple lightweight Movable Type plugin for displaying embedded meta data in either keywords or text_more fields represented in a basic XML format." The plug-in uses an XML format with a meta root element and a single layer of XML elements and values, which are then available as key-value pairs to any Movable Type template.

Install the plug-in on your Movable Type server, and choose either the keywords or text_more field for entering geographic metadata. (We'll assume keywords from here on.) Make sure that field is visible on the Edit Entry screen, via the "Customize the display of this page" link. When writing an entry, you can specify the location of the entry with a small bit of markup, indicating its latitude and longitude:

 36.9716
 -122.0253

In order for this meta markup to show up in your RSS feed, you'll next need to edit the RSS 2.0 template on the Edit Templates screen, adding the following code. There are several Movable Type tags implemented by the Meta plug-in. Used as follows within an RSS item, a latitude and longitude will be added to the RSS feed whenever they are present:

 
 <$MTMetaValue name="lat"$>
 
 
 <$MTMetaValue name="lon"$>
 

Finally, don't forget to declare the geo namespace, by adding the following attribute to the root element:

xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">

This technique can also be used to add location tags to your RSS 1.0 feed, by applying the same changes to your RSS 1.0 Index template. In RSS 1.0, the root element is rdf:RDF instead of rss, but other than that, the details are identical.

 

4.5.2. Adding Location Tags to Radio Userland

For Radio Userland, it's a bit of an easier ride to get to RSS2+Geo. The Location tool (http://radio.weblogs.com/0100875/location/) uses Radio's callback mechanisms to add latitude and longitude inputs to the post form and includes those entries in the RSS file. Simply download and install the tool, and you're all set.

The Location tool also defines a <%locationlink%> tag, which displays a small globe linking to a map of the location specified. You can add it to your itemTemplate.txt like so:

<%locationlink(<%itemNum%>)%>

Congratulations, your weblog posts are now location-enabled and ready to be mapped, for example, with RDFMapper [Hack #21] ! See http://www.mapbureau.com/rdfmapper/ for more on this, or the next hack [Hack #39] for a related hack.

Mikel Maron





Mapping Hacks
Mapping Hacks: Tips & Tools for Electronic Cartography
ISBN: 0596007035
EAN: 2147483647
Year: 2004
Pages: 172
Simiral book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net