Google Maps API
I started working some with the Google Maps API, and it’s pretty nice. The documentation is decent, the examples are good, etc. I realized that I’ve come to expect this from Google, so I wanted to take the time instead to point out that this is an exceptional product. For example, I began to look into making the scroll wheel zoom on my maps like they do on the Google Maps site. What does it entail? One line:
map.enableScrollWheelZoom();
However, as great of a product as it is, it seems to be lacking some things. For example, if I want an info window that gives the options to get directions to or from that location, I have to do all that myself. I have to generate the links, and make them replace the content of the info window with a form that I have to make, and I have to make that form run some JavaScript when executed to get the directions. Why? This has GOT to be a common task. Why not build it into the API? However, in the end, that pales in comparison to the real problem. There is no way to validate a Google Maps API key! Instead, you have to load JavaScript using that key, and it uses an alert to announce that the key was bad! No one wants a JavaScript alert to pop up on their page! Since I’m making a WordPress plugin out of this (teaser!), I needed to make sure that the users of my plugin wouldn’t have this issue. I ended up having to override the alert function on the options page for my plugin like this:
var KillAlerts = true;
var realAlert = alert;
var alert = new Function('a', 'if(!KillAlerts){realAlert(a)}');Then I added a function that runs on page load, re-enables the alerts, and checks if the key was valid:
function load()
{
// Re-anable alerts
KillAlerts = false;
if (GBrowserIsCompatible()) {
// Key is valid
} else {
if (G_INCOMPAT) {
// Key is NOT valid.
} else {
// Can't tell if the Google API Key is valid, due to the browser not being compatible with the Google Maps API.
}
}
}There is no reason that it should be that complicated. They should have a web service where I can send a request to verify a key, or their script should set a global variable rather than send an ugly alert! In the end, it’s a great product, but I would have expected that these kind of rough edges would have been taken care of by now. Google, you make me sad.


