Hack 7. Inside Google Maps URLs

Gain control of your links to Google Maps by understanding the URLs.

"Share Google Maps" [Hack #6] showed how to have Google Maps generate a link (i.e., Uniform Resource Locator or URL) that creates a view of the current map. A little exploration of Google Maps URLs can provide a lot of power!

We have no particular inside information, so much of what followsespecially what I think the abbreviated names stand foris just semi-knowledgeable guesses. Let's start with a basic URL. This is what you get if you search for Key West, Fl and then click on "Link to this page."


The http://maps.google.com part should be familiar. This is the basic Google Maps address. Next, /maps is a program running on Google's servers that generates maps. Web programs can accept parameters. The syntax for parameters is to start with a question mark and then put the name of a parameter, an equal sign, and the value of the parameter. If you need a second (or third, or more) parameter, you put an ampersand between the first value and the second parameter's name. So ?q=Key+West,+Fl&hl=en means there is a parameter named q with the value Key+West,+Fl and a parameter named hl with the value en.

Note that the spaces in "Key West, Fl" have been replaced with plus signs. This is because spaces aren't allowed in URLs and must be escaped.

The parameter hl is the language for the results, and q is the query, or location that you are searching for. If you speak French, replace the en with fr, and so on. If you leave off the hl parameter, Google Maps will try to display things in whatever language the user's web browser prefers.

The q or query parameter can be any of the things that are discussed in "Find Yourself (and Others) on Google Maps" [Hack #2]. For example, here is the URL to a map for latitude 38 degrees north, longitude 122 degrees west:


Google Maps follows the convention observed by most web mapping software and Geographic Information Systems, and uses negative values to denote latitude south of the Equator and longitude west of the Prime Meridian.

Here, for example, is ZIP Code 94305:


The query string for driving directions matches what you would enter into the search box, which is just as you'd expect. Here is San Francisco International (SFO) to Los Angeles International (LAX):


The spn parameter shows how much territory the map spans. It appears to be the number of degrees of longitude and latitude (in that order) that are shown on the map. The first value appears to be the number of degrees of longitude that are shown to the left and right of the center of the map. The second value is the same for the number of degrees of latitude that are shown above and below the center point.

For example, if the values are 1,1, then about 2 degrees of longitude (about 90 miles from east to west), and about 2 degrees of latitude (around 138 miles from north to south) are shown on the map.

When you search for driving directions, the span of the map is automatically set so that both the starting and ending points are shown. The span sets the zoom level. The fully zoomed-out map has a span of 63.750000, 110.319191, while the fully zoomed-in map is 0.003891, 0.006733 (at least for one sample mapit is likely that this varies with latitude). At this point it doesn't appear that you can manually enter an even smaller span. The system seems to have a minimum, beyond which it will not go.

At the equator, one degree of latitude or longitude is equal to about 69 miles, or 111 kilometers. As you go north or south of the equator, the degrees of latitude remain the same, but one degree of longitude shortens to approximately the cosine of the latitude multiplied by 69 miles. So, at 40 degrees north latitude, a degree of longitude is about 46 miles.


1.8.1. More Parameters!

Table 1-2 lists the parameters we've been able to figure out. Here, for one example, is a search for "pizza" when the span of the map has already been limited to a local area:


The parameter sspn appears to be the search span, and sll is the search's latitude, longitude center pointso this query is looking for pizza within .031128 degrees of longitude and .053867 degrees of latitude from latitude and longitude 38.402193, -122.829009.

For linguistic reasons, we tend to think latitude and then longitude (i.e., lat/long), but when we draw graphs we think x,y. Latitude maps to the y axis, so to be consistent we'd talk about either y,x graphs or latitude, longitude coordinates. Google appears to have adopted both conventions in expressing geographic coordinates in this URL. People are not consistent, and Google can happily have a URL that specifies the center point as latitude, longitude but the span in x,y.

To see the satellite view, add the parameter and value t=k. Maybe that means type is k? What could k mean? (keyhole, perhaps?) As of August 2005, the letter k and the number 1 both cause a satellite map to appear, and the letter h causes hybrid maps to appear. From experimentation (i.e., trying all the other letters), no other special tricks live in the t parameter. Perhaps the other letters and digits will be used for coming features.

This URL represents a satellite view and driving directions from SFO to LAX:


Or, to get just the driving directions:


Table 1-2. Google Maps URL parameters







Query string. This is what goes into the single search box.









Imagery type. Show satellite imagery if set to k or 1 and hybrid maps if set to h.


-122.7 38.4

Longitude and latitude of the center point of a generated map.



Zoom level. Ranges from 3 to 18.


5.603027 7.481689

Number of degrees of longitude and latitude across the entire map.


0.031128 0.053867

Search span. Define area to search for local search. Same format as the spn parameter.


38.403193 -122.82709

Search latitude and longitude. The center point for a local search.


1.8.2. Finding More Parameters?

Another cute thing you can do with Google Maps queries is to add a custom title to the location by putting the title in parentheses after the search location. For example, the following URL shows the location of Google's headquarters, titled with the word "Google":


Google Maps is filled with hidden (to us) options. The way to find out what it can do is to experiment! Try different things and to see what it all means, click on "Link to this page" often! You never know what might workthat is the essence of hacking!

1.8.3. See Also

  • "Generate Links to Google Maps in a Spreadsheet" [Hack #8].

You Are Here: Introducing Google Maps

Introducing the Google Maps API

Mashing Up Google Maps

On the Road with Google Maps

Google Maps in Words and Pictures

API Tips and Tricks

Extreme Google Maps Hacks

show all menu

Google Maps Hacks
Google Maps Hacks: Tips & Tools for Geographic Searching and Remixing
ISBN: 0596101619
EAN: 2147483647
Year: N/A
Pages: 131
Similar book on Amazon

Flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net