Megan Taylor

front-end dev, volunteacher, news & data junkie, bibliophile, Flyers fan, sci-fi geek and kitteh servant

Adding maps to FireTracker

After working through Andy Boyle’s FireTracker tutorial series, I decided to take things a step further. Gotta have maps!

So I Googled around for a way to do that. I found django-easy-maps, and after just a few changes to Andy’s original models, I had me some maps.

NOTE: YOU MUST HAVE DATA IN YOUR APP BEFORE YOU DO THIS OR YOU WILL NOT SEE ANY MAPS AND THEN YOU WILL COME CRYING TO ME ABOUT IT.

Here’s how to do it:

1. Go to django-easy-maps and follow the installation instructions. If you don’t use pip, easy_install will work too.

Install django-easy-maps in the same directory as your fires app. Make sure to add the app to your INSTALLED_APPS in settings.py.

2. You need to make a little change to Andy’s original models.

In models.py, find this class:

And make it look like this:

3. Now, because you’ve changed the models, you have to sync those changes to the database. So run manage.py syncdb. Then restart your server.

4. One more change! Open up the templates folder. Open up index.html (or whichever template you want to have the map) and type

wherever you want the map to appear, but AFTER {% for f in fires %}.

EDIT: The 200 200 bit tells the map what size to be. In this case, my maps are 200px wide by 200px tall. You can change that to suit your design.

Wheee! Mappage!

Basically, all we’ve done is created a new variable that will print “state, city, address”. We use that variable in the easy_maps template tag (that’s this bit: {% easy_map VARIABLE 200 200 %}). And easy_maps does the rest!

(h/t to Ken Schwencke and Jamie Wilson for helping me with this!)

July 12, 2011 | Comments Off on Adding maps to FireTracker | Categories: Posts | Permalink

Comments are closed.

%d bloggers like this: