Google Maps

Now, let’s turn to studying the functionality of Google Maps, located at

With the standard Google Maps site, you can do the following:

You can also embed a Google Maps “widget” into a web page via JavaScript—using the Google Maps API.[34]

Even though Google Maps is not the most highly trafficked online map site,[35]

URL Language of Google Maps

Understanding the syntax and semantics of URLs in Google Maps will help you better recombine the functionality of the standard Google Maps site. Consider an example: I have an address I want to locate—for instance, the address of the White House (1600 Pennsylvania Ave., Washington, D.C.). I go to Google Maps ( and type 1600 Pennsylvania Ave, Washington, DC into the search box to get a map. I get the URL for the map by examining the “Link to this page” link:,+Washington,+DC&sll=36.60585,-121.858956&sspn=0.006313,0.01133&ie=UTF8&z=16&om=1&iwloc=addr

What do the various parameters in the URL mean? Table 2-4 draws from the Google Maps Parameters page of the Mapki wiki.[36]

Table 2.4. Dissecting Parameters for a Link to Google Maps
Parameter Description
f=q The f parameter, which controls the display of the Google Maps form, can be d (for the directions form or l for the local form). Without the f parameter, the default search form is displayed.
hl=en Google Maps supports a limited number of host languages, including en for English and fr for French.
q=1600+Pennsylvania+Ave,+Washington,+DC The value of the q parameter is treated as though it were entered via the query box at
sll=36.60585,-121.858956 sllcontains the latitude and longitude for the center point around which a business search is performed.
spn=0.006313, 0.01133 spn is the approximate latitude/longitude span for the map.
ie=UTF8 ie is the character encoding for the map.
om=1 om determines whether to include an overview map. With om=0 the overview map is closed.
iwloc=addr iwloc controls display options for the info window.

A good way to get a feel for how these parameters function is to change a parameter, add new ones, or drop ones in the sample URL and take a look at the resulting map. For instance, if you have only the q parameter, you would still get a map with some default behavior:,+Washington,+DC

That is, the other parameters are not mandatory. Let’s play with the z parameter to adjust the zoom factor:,+Washington,+DC&z=0

versus the following:,+Washington,+DC&z=17

There is a comprehensive list of Google Maps parameters[37]

Just as you can create mashups involving Flickr by using Flickr’s URL language, you can create mashups with Google Maps by exploiting its URL structures. Let’s consider a few examples.

Viewing KML Files in Google Maps

Many of the popular sources for KML (such as assume you will view KML in Google Earth. However, you can display a limited subset of KML in Google Maps. Consider, for instance, the KML file at the following location:

It can be viewed in Google Maps by passing in the URL of the KML file via the q parameter, as shown here:

Hence, in your own web site, you can give the option to your users of downloading KML to Google Earth or viewing the KML on Google Maps by linking to the following:{URL-of-KML}

Connecting Yahoo! Pipes and Google Maps

A specific case of displaying KML files is feeding KML from Yahoo! Pipes into Google Maps. (I describe Yahoo! Pipes in detail in Chapter 4. For the purposes of this discussion, you need to know only that Yahoo! Pipes can generate KML output.) Consider, for example, Apartment Near Something, configured specifically to list apartments that are close to cafes around UC Berkeley:

You can get KML output from Yahoo! Pipes from the following:

which you can feed into Google Maps in the q={URL-of-KML} parameter:,-122.24556&spn=0.189398,0.362549&z=12&om=1

Other Simple Applications of the Google Maps URL Language

Here are a few other examples of how to connect Google Maps to your applications by creating the appropriate URL:

  • Let’s not forget that by just using q={address}, you can now generate a URL to a map centered around that address. If such a map suffices, it’s hard to imagine a simpler way to create a map corresponding to that address. No geocoding is needed.

  • You can create a URL for custom driving directions for any source and destination address creating custom driving directions from your spreadsheet of addresses by making the URLs. For example, to generate driving directions from Apress to the Computer History Museum, you can use this:{source-address}&daddr={destination-address}

    to generate this:,+Berkeley,+CA+94705&daddr=1401+N+Shoreline+Blvd,+Mountain+View,+CA+94043

    Although driving directions have recently been added to the Google Maps API, [38]it is currently not possible to use the API to create directions to avoid highways, something you can do by using the dirflg=h parameter.[39] Hence, you can easily generate a scenic route for myself between the Apress offices and the Computer Museum, while avoiding the API altogether:,+Berkeley,+CA+94705&daddr=1401+N+Shoreline+Blvd,+Mountain+View,+CA+94043&dirflg=h

    It pays to know the URL language of an application!

  • You can use Google Maps as a nonprogrammer’s geocoder. Center the map on the point for which you want to calculate its latitude and longitude, and read the values off the ll parameter. If the ll parameter is not present, you can double-­click the center of the map, just enough to cause the map to recenter on the requested point.

[35]—“Google’s maps already are a big draw, with 22.2 million U.S. visitors during February, according to the most recent data available from comScore Media Metrix. That ranked Google Maps third in its category, trailing AOL’s Mapquest (45.1 million visitors) and Yahoo (29.1 million visitors).”