Poll-by-Poll Google Maps Now Added
Following up on my last post from just over a month ago, I can now report some success in adding coloured, interactive poll-by-poll Google Maps to the Pundits' Guide website.
For every current riding, if you now click on the "Google Maps" tab, it takes a second, and then a poll-by-poll map appears of the 2008 General Election results, showing the winner of each polling division (note that this could roll up the winner across 2 or more polling stations for that polling division, or show the winner of the polling station into which the polling division was merged).
Those of you who follow me on Twitter @punditsguide got an early look at the maps Sunday night, and got to send in requests for links for me to post. Here's a colourful example from Gatineau, QC, which was the closest 4-way race in the country in the last election (click on the map to take you to the page with the interactive version of it):

It was a huge chunk of work to get this far, but naturally I'm still fretting more about what isn't working yet:
- I still don't handle ties properly; so for the time being the winner is arbitrarily assigned as the candidate having the lowest candidate_id value.
- All the markers, which represent the apartment and mobile polls, are still showing up blue, regardless of who won the poll. To fix that I need to find the online location of all Google's other marker icons; and if anyone out there has the URL could you please sent it urgently, otherwise Olivia Chow and Bob Rae might have heart attacks when they look at the maps of their downtown Toronto ridings. (Trinity – Spadina, ON and Toronto Centre, ON have almost 100 apartment polls each.)
- In another colour-related concern, the colours for the Bloc Québécois and the Conservative Party are a bit hard to distinguish. Of course I don't want to make the colours too dark, or you wouldn't be able to see through the transparency to what is actually located in a given polling division, but I'm going to have to come up with a slightly greener blue for the Bloc more along the lines of their older colours (similar to what I do for them in some of the financial charts).
- So far, I'm only showing the 2008 General Election, although I do have the ability to show every election (including by-elections and the transposition) since 1999. Unfortunately, there's a pesky bug in my code, which will require a good night's sleep, a second set of eyes, or maybe even an @atomicnoggin to locate and correct. This means that for the four ridings who've since had by-elections, the latest results are not being automatically returned, however I'll write them up in the next post so you can eyeball them instead. A similar problem is occurring for the older (i.e., last redistribution) ridings.
- The poll number pops up if you click on a polling division, but so far no other information, although I have plenty more I can add down the road.
- I haven't produce regional or provincial maps yet, and am not sure if that would be technically feasible size-wise yet.
http://punditsguide.ca/riding_e.php?riding=1138&pane=3
(It doesn't matter whether you put a "www." in front or not.)
I've added enough of Google's navigation functionality so that you can zoom in and out and pan all around with your mouse or the arrows, and you can also switch between the Map, Satellite and other views. The map automatically centres and zooms itself when you first load it, but it's done in such a way that you can see the whole riding ... which gets weird in cases like Halifax, NS (which includes Sable Island), or Nunavut, NU (which is so big that it gets rendered automatically on a map of the entire planet).
It could go without saying, but probably shouldn't, that none of this work would have been possible without the commitment of the Chief Electoral Officer to make both the poll-by-poll results and the polling division geospatial boundary "shape files" available to the public, nor without the invaluable GeoGratis.ca website hosted by Natural Resources Canada which makes files of that size available for download for mappers, both amateur and professional.
It was a very steep learning curve for me to figure out how to do all of this, but certainly having access to all the data assisted that process greatly. Thank you.
It's also amazing what infrastructure Google is providing (so far) for free, including their amazing mapping API. For the super-technical readers, I'm now generating KML on the fly from my database of polling divisions and polling division shape file data, compressing it into a KMZ file in-memory and then returning it to the GGeoXML object in that API. I had to switch from gzip'ed KML to KMZ because I ran into their 4 megabyte hard limit on fetched KML/KMZ data with most of the rural ridings. I think the end result is pretty fast all things considered, but if your experience differs, please let me know in the comments. Unfortunately I'm not able to offer support along the lines of "Google Maps aren't showing up in my browser", however, although if you Google that error, you'll come up with a lot of suggestions to fix the problem on your machine.
So, what suggestions can you offer, dear readers, to improve the interface and interactivity of these maps? Please leave any feedback in the comment section, or drop me a line by email.
With this big item out of the way, although I'll be back to semi-regular blogging now and getting the nominations back up to date, there will be some other big changes going on with the website in coming weeks. For one thing, Google's decision to terminate FTP publishing of blogs that use the Blogger interface on May 1 means that I have to move that aspect of the site over to a local Wordpress installation, and I'll be taking the opportunity to significantly improve the design, layout and organization of the site, with the help of @atomicnoggin and @iancapstick.
So, there may be a few hiccups in coming weeks, but I hope you'll be patient and not give up on it yet. Meantime, enjoy the maps!
Labels: Google Maps, Open Government Data




