Sponsored Links

Technical Overview: Google Mapplets PDF Print E-mail
Written by Richard Marsden   
Monday, 31 August 2009 09:32

Google Mapplets are small map gadgets which can be hosted by Google and operate alongside the main Google Maps application. They can be a very convenient way of building small map applications without having to create your own webpages on your own website. Google looks after the wider GUI elements and map housekeeping, leaving the developer to concentrate on the application specifics.

 

In order to create a Google Mapplet, you will need a Google account. A GMail account is sufficient, but you can create a new account here. You will then need to install the Mapplet Developer Tools into your Google Maps configuration. First sign into Google with your Google account. Next, navigate to the Developer Tools section of the Google Maps Directory, at: http://maps.google.com/ig/directory?synd=mpl&pid=mpl&cat=devtools

From this page, install the following tools:

  • Mapplet Scratch Pad. This is used to write the mapplet
  • Developer Mapplet. This adds an important Reload button which circumvents Google's default caching, and is essential for testing.
  • API Reference Mapplet. This displays all Mapplet API calls.

 

Next, navigate to http://maps.google.com/maps/mm, and sign in with your Google account. Select the scratchpad, and start typing your mapplet in!

Google Mapplets are based on the standard Google Maps API, but the code is wrapped in XML. The best demonstration of this and how it interacts with the Google user interface, is to look at an example. Here is the Google "Hello World" (italics) sample:

ERROR [include_code_listing plugin]: File Not Found (/usr/www/users/winwaed/geowebguru/img/2009/mapplet_sample1.xml)


The mapplet consists of a Module tag. The ModulePrefs tag provides metadata such as the title and author. It is also a good idea to provide a thumbnail for use by the Google Directory when the mapplet is published.

The actual mapplet code is standard HTML contained within a Content tag. Note that this also requires a CDATA section so that the HTML and JavaScript are included properly.

HTML text appears in the mapplet's text window on the left. This particular mapplet simply displays one line of explanatory text ("This example zooms out...").

The JavaScript provides the actual functionality. This is enclosed in a conventional script tag. A map (GMap2) object and a point (GLatLng) object are created using the standard Google Maps API. The map is positioned on the data point and set to zoom 2 (ie. zoomed out). A marker with an info window message of "Hello World!" is added at the point. The info window is set to open automatically when the user clicks on the marker, using GEvent.addListener to set a callback.

Test your mapplet by pressing the Preview button, and you should see something like this:

Screenshot of the Mapplet - click for larger image

 

When you are happy that the mapplet is working properly, you will probably want to install it so that it can be shared with other Google Maps users. To do this, you need to host it on a public website - you can use a Google server if you wish. You can then publish it, share it, and submit it to the Google Directory. Full instructions as to how to do this can be found at: http://code.google.com/apis/maps/documentation/mapplets/guide.html#Publishing

On the downside, Google mapplets do have a couple of potential problems. First, all communication with the map is asynchronous. This means a simple query such as fetching the map's central position are asynchronous. This can make some map operations more cumbersome.

The second is the XML "sandbox" imposed by the browser. This makes it difficult for a script to read a file from a different website. As all Mapplets run from a Google domain, this restricts the ability to read third party data feeds or even data feeds on your own website. External data feeds such as these must be read using the special proxy functions _IG_FetchContent(), and _IG_FetchXmlContent that are provided by Google.

So in summary, Google Mapplets can be a useful way of creating small map applications that are hosted by Google and work alongside the main Google Maps application. Initial development is simplified by Google handling much of the housekeeping. However, more sophisticated development can become more complex than a tradition Google Maps application.