Viewing posts tagged with: Google Maps

April 14th, 2008 Google Maps for Wordpress

Download from wordpress.org

Warning: This plugin was affected by Trac ticket 6444, which was fixed in WordPress 2.5.1, so get 2.5.1!

The Google Maps for WordPress plugin allows you to easily insert Google maps into your blog, making use of the new shortCode system in WordPress 2.5. The maps can be configured to offer directions to or from the location, show or hide the zoom/pan controls, show/hide map type, activate zoom using mouse wheel, and more.

It requires a Google Maps API key, and then gives you a nice interface near your editor to help you build the map and send it to the editor.

March 28th, 2008 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.

Search