I felt very clever when I discovered how to get to the actual KML exported as part of the “View in Google Earth” feature of Google’s MyMaps area of Google Maps. I still don’t know why I didn’t make the leap sooner from downloading the data to using it live in an application. Although I figured it out on my own, I would have made the “discovery” sooner if I just had read Mike Williams Google Maps API Tutorial with a closer eye to detail. My one excuse is that I didn’t originally use alternatives to Google’s own GGeoXML class. Now that I’m collaborating with multiple map maintainers, I don’t want to go through the whole download/massage/publish cycle. Instead I want to use the excellent editing and collaboration facilities of the MyMaps interface to allow others to keep things updated properly.
In the spirit of sharing, I want to walk you through the process of going from MyMaps to your own hosted map using that data as an overlay.
- Get a Google Account
- Sign in and Visit Google Maps
- Create your first My Map. Click the My Maps link in the left side bar, then click Create New Map.
- Set the center point and map display type using the normal maps interface.
- Edit the map by using the Edit button.
- Save the map using the Save button.
Note that you can add polylines and markers to your map, as well as edit the marker information as plain text, rich text, or HTML. You can pick icons for your markers or add your own. Note that adding your own doesn’t add to a data store, but uses a URL reference. If you don’t maintain or control the server hosting the image, you won’t be able to guarantee that your custom marker will always be available.
When you’re happy with your map, use the View in Google Earth link above the map display itself (between RSS and Print). Instead of letting Google Earth load the file, save it to your computer.
To help with my examples, I created a Demo Map Showing East Carolina University in my public Google account. The link in my blog post was created by using the handy Link link within the interface.
You’ll note that the file size of the kml file is very small, which if you’ve created many markers with detailed information will seem confusing. This XML doesn’t contain your data, but contains a URL to your data. For instance, here is the contents of the KML file exported for my demo map:
Demo Map Showing East Carolina University
The important feature of this file is the href element inside that link element. That’s the URL we want to our actual KML data. If we with to use it with GGeoXML, we can just replace the entities with their single character equivalents and construct the layer:
geoXml = new GGeoXml("http://maps.google.com/maps/ms?ie=UTF8&hl=en&oe=UTF8&msa=0&msid=113918317131300723802.00047c45b431d9dc64cb7&output=kml");
That’s all there is to it. Now if you or any collaborator edits the map, the next time it’s reloaded the GGeoXML class will pick up the latest version. Next time I’ll discuss using the much more advanced Geoxml class. It requires one more bit of work because it cannot load data from URLs that are not within the same domain.