Maps provided by Google can be embedded into a website using three approaches. The first approach consists in simply creating a custom map via the custom map editor. It allows you to add placemarks, draw lines and shapes, and publish your map for public consumption. The map can be then embedded in your website.

The second approach consists in customizing the map via javascript using the Google Maps JavaScript API.

The downside of these two approaches is that it requires the client to download complex pieces of JavaScript. With mobiles, the bandwidth is always a bottleneck. Additional, the clients on some older mobiles may not be advanced or powerful enough to let the user interact, and in some cases, view the map.

The third option then consists in relying on static images to deliver maps. Google provides such a functionality via the Static Maps API. This service creates a map based on URL parameters sent through a standard HTTP request and returns the map as an image that can be displayed on the web page. Similarly to custom maps, placemarks and lines can be added via additional URL parameters.

A common scenario is to create and publish a custom map, and choose to convert it later to a static image for an easier consumption by mobiles. Unfortunately, there is no built-in mechanism to convert a custom map to an equivalent static map. The solution starts by downloading the KML file of your custom map. As KML is based on the XML standard, it can be processed by a XSL transformation to generate a static URL with a format compatible with the Google Static Maps API. </p>

To illustrate the process, I have created a custom map listing the places where I worked. I have then downloaded the related KML file. The structure of this file is easy to follow as it is a collection of placemarks defined by a name, a set of coordinates, and a style. In the following excerpt, the placemark “Boca Raton” is associated to style 9 which is, in turn, rendered by a red dot.

    <name>Boca Raton, FL</name>
    <description><![CDATA[See  <a href="" target="_blank">details</a>.]]></description>
<Style id="style9">

I have included below an example of a XSL transformation which identifies all the placemark tags and produces the final image URL. For each of these tags, the related style is located and the final color of the marker is extracted. The first letter of the name of the placemark is used as the label in the final transformation. The XSL transformation can be adapted to accommodate more complex scenarios such as the rending of lines or shapes.

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="" xmlns:kml="" >
<xsl:template match="/">
  <xsl:apply-templates select="kml:kml/kml:Document"/>

<xsl:template match="kml:kml/kml:Document">
  <xsl:for-each select="kml:Placemark">    
    <xsl:variable name="styleUrlId" select="substring-after(kml:styleUrl, '#')" />
    <xsl:variable name="styleUrl" select="../kml:Style[@id=$styleUrlId]/kml:IconStyle/kml:Icon/kml:href" />
    <xsl:variable name="color" select="substring-after(substring-before($styleUrl, '-dot.png'),'micons/')" />
    <xsl:value-of select="$color" />
    <xsl:value-of select="substring(kml:name,1, 1)"/>
    <xsl:value-of select="substring-before(substring-after(kml:Point/kml:coordinates, ','), ',')"/>
    <xsl:value-of select="substring-before(kml:Point/kml:coordinates, ',')"/>


The end result follows. The first map is created using the Google Static Map API, while the second map is simply created by embedding the custom map directly in the page.

Google map defined as an image URL

Google Map defined in a HTML frame