Wednesday, May 12, 2010

Bing Maps, Google Earth, and further misadventures with KML

Today I got to play around with some geographical data, and I felt amazed by how far we've come. Back in 2004, I was still reduced to plotting customers on a map by sticking latitude and longitude into Excel, making a scatter graph, and looking at the results, which resembled a bowl of peas that had been stuck to a map of Britain.

This was a satisfying thing to do, in that it was ugly and a brute force approach to handling data, and besides which, we were all using Apple Macs which wouldn't run Google Earth, and in any case I was feeling punchy and didn't want anything to do with XML in any form, thank you very much.

Grind through a few years, and I'm doing much the same thing, except this time for things in Japan, and although to begin with I'm quite happy with another scattergram in Excel, as soon as somebody points out it would be nice to overlay a map, and off I go with a fistful of coordinates, looking for a nice way to get them on a map.

Now I could go and use Google Maps, but either I'm a glutton for punishment or else I just want to be different, but I try Bing Maps first. And it's horrendous. Really horrible. If you search for simple things like "bing maps api" on Bing, you don't immediately get a bunch of helpful info up, and when, after a little digging, you do find some examples and tutorials, nothing works quite right. (Actually, that might be due to setting my preferences in Bing to Japan, but that's something Bing did for me, and keeps doing, no matter how long I live in Hong Kong or tell it that I want the US English set up).

There's a helpful tutorial on a way to handle displaying lots of points at the same time, without getting cluttered.

Except the .png files it supplies don't work properly, so instead of your version of the example looking like the example, it looks like somebody stuck a bunch of really crappy pushpin icons over a map, and you're reduced to going and getting a decent pushpin icon from Google instead. Which I doubt was really the intention of the tutorial. Unless they just wanted you to say "hmm, PNG looks a bit rubbish. Let's jack it in and use Google Maps instead."

There's also some fairly ugly documentation on bits and pieces of the code, with at least three different ways of embedding maps, but the nice, obvious things like showing what size a map should be, or getting it to initialise on a centre point of your choosing, rather than the middle of the US, take a lot of looking for.

And then don't work.

Finally, you don't seem to be able to go west further than Hawaii.1 Is this a bug? Is this a feature? Is it something special about this particular tutorial?

Still, pleased I'd got as far as bodging some data into a map on a web page, until a coworker mentioned Google Earth and kml files, and I felt a little embarrassed at the previous hour's expenditure of time, and tried building a kml file instead.

This wasted an hour quite profitably, in which I learned that:

Kml expects longitude - latitude coordinate, not latitude - longitude like everyone I've ever met in my life. So that was half an hour wasted before I paid attention to the documentation. At least the Bing input was happy with distinct and unambiguous <geo:lat> and <geo:long> elements.

Kml also is a little more awkward than the xml feed the Bing example consumes. I spent another ten minutes wondering why a file full of <Placename>s was only loading the first element, when I suppose if I'd read the documentation more intently, I'd have realised it needed wrapping in <Folder> tags. But then if all the documentation is there and you don't read it, that's tough.

So in conclusion, using kml and Google Earth works more nicely than Bing Maps, if and when you read the documentation, but you have to do it properly. Whereas Bing seems easier to bodge something together quickly, but then doesn't work properly. Is that pragmatism vs pedanticism? Is Ballmer a chancer and Sergei an annoyingly correct Russian? Or am I just making wild generalisations based on a couple of hours of coding?

1 Don't worry, young man. You can still go East to get to Japan. But really.

0 comments:

Post a Comment