Integrating KML into Google Maps

Posted: December 31, 2007

After getting a GPS unit over the holidays, I was keen to try mapping out a hiking trail on the Vancouver Trails site. After importing the tracks into MapSource and cleaning a few points up, I saved the file in .gpx format and imported that into Google Earth. It looked great!

From here, I could right-click on the data folder and export it to .kml or .kmz format.

To integrate KML files into Google Maps on your website, add the following lines of javascript after the map.addControl calls:

var kml = new GGeoXml("kml-file.kml");

The first file that I exported to .kml from Google Earth was over 250K and included thousands of lines of useless style code. So, I exported the Tracks as one file and then the Waypoints as another file and used the code above twice, once to load each file. Both of those files combined were much smaller at just 21K combined.

The only thing left was to export everything into one .kmz file and provide a link under the map so that users could click and the link would open the map into Google Earth automatically. Click here to open the Capilano Canyon file in Google Earth.

Capilano Canyon Map

Leave a Reply

Your email address will not be published. Required fields are marked *