Friday, April 04, 2008

Mildly Interesting KML+Google Maps Bug

Google map keys are of course tied to a particular base URL. You can get a key for http://localhost for development, but you may have noticed this isn't necessary: maps will load correctly in http://localhost/ for any map key.

However, you can't load KML into your maps on localhost unless you are using a key for http://localhost. That is, your map will load but the KML overlay wont' be added. That is,

geoXml=new GGeoXml("http://mapgadgets.googlepages.com/cta.kml");
map.addOverlay(geoXml);

won't add the overlay to your map if you are using mismatched keys. To see this in inaction, try serving up the code sample http://code.google.com/apis/maps/documentation/examples/geoxml-kml.html
from your own web server (using your own key, of course). First try using localhost:8080 and then use http://your.real.server.name:8080/. This assumes the google key was generated for http://your.real.server.name:8080/.

No comments: