Rich's Adventures with Google Maps & Fusion Tables
Something came along the other day that caught my attention. The 'brief' was to create an interactive map that displayed countries based on a 'risk' level. That was it. (after all, it was just a prototype, to see a) what was possible and b) the best way to go about this.)
Obviously, it was Google Maps that was the immediate front-runner for this.. I've tinkered with gmaps a little in the past, but not really delved into what you can actually achieve. A previous project I'd worked on called for an interactive map,with custom routes that didnt stick to any roads. (I'll cover that in a seperate post).
Initial steps
My first foray into coding this hinged on what I'd done in previous projects.. namely plotting the points using some very handy sites that let you plot your points, then gave you the javascript code for the latitude and longitude for each point.
After mapping out two countries by hand, I realised that this was futile task. Not only would it take you aaages to map out each country that you wanted (depending on how 'close' to the actual country borders you wanted to go. Having fairly coarse points worked ok when zoomed right out, but as soon as you zoomed in closer, you could see that the points did not match the borders), it would also be a right pain to maintain, or add new 'countries'.
Plotting points by hand = off the cards. Time for a re-think.
KML files
A bit more research, and I discovered KML (Keyhole Markup Language) files. Now some of you may be thinking "err.. little late to the game, arn't you?". Well, yes. But hey-ho!
So KML files are basically XML files, which can contain one or more
A quick google around brought me a KML file of all the worlds country borders in one handy file. Bonus!
Half my work is done!
Quickly dropping the required code into a page resulted in.... nothing. Just a normal map. no borders or anything. Hmm.
A quick scan of the documentation resulted in the titbit of information I missed earlier. In order for Google Maps to successfully parse a KML file, it needs to be hosted on a public, internet-facing site. Doh!
It makes sense though, Google reads the information in the file, then geo-codes the locations on their servers, and sends back the map layers to you.
Ok, attempt no2. Upload the KML file to my Google Drive lcoation, and amend the source code accordingly. a quick Ctrl-F5 then resulted in the map appearing. Success! However, it had put a nice blue border around EVERY country on the map. Hmm, lets sort that out.
A scan of the KML file, and I spotted the