Drupal 7 Geotagging and Silverlight Maps

Raised Eyebrow is currently working with Microsoft on a multi-faceted Drupal 7 project. One of the project's technical requirements involves displaying nodes that have been tagged with Geographical information on a Silverlight Map.

As part of the requirements gathering phase of the project we were given access to a recently built Drupal 6 site - http://bhangra.me, which features just such a Silverlight map on its homepage, to provide a base for how we would create similar functionality in Drupal 7. Our job has been to decipher how the map on bhangra.me functioned and then replicate that in Drupal 7. 

The Easy (Silverlight) Part

I say easy, because it was the easy part for me. The Silverlight Control was developed externally and was cleverly built to accept and parse an XML/RSS feed from Drupal (or elsewhere). This RSS feed contained some simple Geographical information stored as so:

<georss:point>49.283381 -123.110995</georss:point>

It was built to accept the default Drupal promote to homepage RSS feed which lives at http://example.com/rss.xml. If you want to pass it a different feed using Views, you will have to set the URL of the View display to override rss.xml.

The Drupal 6 Part

As I mentioned previously, the bhangra.me was built using Drupal 6, and the requirement for this project was that the site be built using Drupal 7. On close examination of the functionality of the bhangra.me site I observed that the following modules were being used to collect and display geographical data:

The Openlayers module in Drupal 6 provides a simple OpenLayers WKT field type for storing complex geodata like points, lines, and polygons. It has a wonderful autocomplete address search field, with a map, which works wonderfully when typing in an address and it also geocodes on the fly:

It's that easy. Install and enable the Open Layers module and add a CCK field of type OpenLayers WKT. Then any node that has this Geographical content that is promoted to the homepage will show up in the rss.xml feed and thus display nicely on the map. Don't forget to choose which API service you're going to use and set up your API keys at http://example.com/admin/build/openlayers/layers/settings.

So what about Drupal 7?

Unfortunately the Open Layers Geocoder module does not have a Drupal 7 version, so the nice autocomplete interface is no longer available. The solution is to abondon the OpenLayers and OpenLayers Geocoder module and use the Location module, which provides similar functionality and allows for Geocoding via Google Maps. Simply download and install the Location module, enable it and the Location CCK module. Add a Location CCK field to your content type, and that should be all you need to do to ensure that the Geographical information needed in the rss.xml is there.

Don't forget to sign up for your Google Maps API key and to enable the Google API geocoding options for your country at http:/example.com/admin/config/content/location/geocoding.

Don't forget to promote

Remember, this Silverlight control pulls in the rss.xml feed in Drupal which is generated using all content that is promoted to the homepage via the node edit form. So if you're content is not appearing in the map, make sure that it's set to "Promote to homepage" and has some Geographical information set in the node.

Where can I get the Silverlight Control?

You can pull it straight from the bhangra.me site if you wish, you can build your own or if you would like to get your hands on the source you could email me and I'll see if I can get it for you.

Can I do this with Google Maps GMap Module?

I don't see why not. I haven't tested this myself but I know that the GMap module has views integration which should allow you to create a block or page view of full nodes that contain Geograhpical information and produce a very similar result. There's a great video tutorial by Sean Effel over on Drupaltherapy.com that might help a lot.