Wednesday, April 21, 2010

Maps to KML?

People often ask me, can I take a Google Maps mashup, and make a KML file out of it (or in some other data format)? This question never comes from a Maps developer, only from people who see a cool mashup and want to overlay the data on their own map.

The short answer is: no, you can't.

The long answer is: no, you can't, and that would be wrong.

The longest answer is: no, you can't, unless the developer chooses to make a KML file available to you. It's possible, in fact, that they are using the KML file loaded onto their map using GeoXml or some other method. Otherwise, no, and it would be wrong.

I can understand the desire to do so. After all, a mashup is a combination of data from different sources, and a Google Maps API mashup is a mashup of data with Google's mapping API, in JavaScript, Flash, or just plain image URLs using the Static Maps API. And people often use public sources, or sources that are about things that are interesting or impacting lots of people, like Sports or the volcanic eruption in Iceland. Why wouldn't that be available to you?

First, from a moral point of view, the construction of that site belongs to the developer of that site. Usually, the data isn't presented to them raw, a certain amount of development has to happen to transform the data into a format usable for the app. In fact, they may have agreements with the data provider that they don't, or some license in the download from a public site restricts redistribution.

Of course, it's possible they just didn't think of it. Ping them, maybe they would do it for you just to be nice. Depends on the data of course.

Second, think about it from a technical point of view. Flash of course is it's own beast, and can write files. If the developer so chose, they could put a download data link or something. But as far as the JavaScript APIs go, JavaScript deliberately doesn't give you file access for security reasons. So a data file can't be taken from a JavaScript page. Nor has Google hidden an API inside the Google Maps API to allow other people to pull data out programatically. Again, that would be wrong.

I'm not saying that people can't look at your code and figure out your data sources, if you're the developer. If you want to protect that data source, you should design accordingly.


Cannonade said...

I saw a question in the google-maps tag on Stack Overflow that asked this very question (it appears that it has since been removed). The general reaction was disapproving grumbling and no answers.

As an author of a mashup involving hundreds of hours of research and data entry I would be more than a little put out if some wiley developer checked out my Javascript and pulled my data.

What do you mean by "design accordingly"? I wonder, outside of obfuscation, how you protect the data used by a Javascript based mashup? As you said, a dev can just look at your code and work out where your data is coming from. Quite wrong, but definitely do-able.

Mano Marks said...

@Cannonade. Sounds like I need another blog post. There's a few approaches, such as using server side calls to restrict access to an entire data set. Obfuscation is another of course. A third is to use tile sets instead of overlays, for instance for intensity maps, or simply making a tile of the marker locations with a transparency, making it difficult to scrape the data. I'll try to put together another post on it in a couple of weeks. Also, check out the official Google Maps API group, I'm sure there's some people with suggestions there.

Cannonade said...

I haven't had a lot of time to devote to securing my data, but those are great ideas to look into. I'm looking forward to reading that blog post. :)