Preface

A few years ago, using maps on the Web was hard. The maps were ugly, slow to load, and burdened with a clunky user interface—and if you think using maps on the Web was hard, imagine trying to make useful and interesting maps on the Web! Today, however, all that has changed. A good measure of the credit for this quantum leap in digital cartography on the Internet is due to Google and their Google Maps service. How did this come about?

Putting the World in the World Wide Web

It has been said that “the network is the computer,” and, for most of us, the “network” means the World Wide Web. From its humble origins as a repository of hypertext documents, the Web has become a sort of distributed operating system, one that allows clever programmers (and more than a few random dilettantes) from far-flung places to build new applications by mixing and matching data and services in ways that the original designers of those services never considered.

In recent years, “traditional” commercial web sites, such as Amazon, eBay, and Google, have increasingly become platforms that support complex user ecosystems. Using openly published APIs, you can look up an item on Amazon, get a price history from eBay, and find reviews on Google—all at once, and all without Amazon, eBay, or Google ever talking with each other.

Until now, a crucial component has been lacking—location. What’s important about location, you may ask? Well, for starters, it’s everywhere! Everything has a location, and until now there were few reasonable options for mixing in location. There were expensive and complicated proprietary systems, as well as free and powerful—but still complicated—open source options, but they all required you to be part of the cartographer’s elite. You had to pay with time, attention, aggravation, and even money! But today, Google Maps has opened mapping to everyone. Ah! Location!

Open APIs + Open Data Formats = Web 2.0 Heaven

Let’s take Paul Rademacher’s HousingMaps site at http://housingmaps.com/ as one example. HousingMaps takes housing rental and for-sale listings from Craigslist and plots them on a Google Map, making it easier to find housing in the area that you’re interested in. HousingMaps demonstrates what can happen when you give developers a toolset—and, mind you, developers don’t even need a clean, well-documented toolset. The site was originally developed by hacking on Google’s (initially) somewhat-obfuscated maps interface. The key is that neither Craigslist nor Google were involved in this endeavor, and that the result was something greater than the parts. In music this is called a mashup, and the term has crossed over and is now used in the world of Web 2.0.

Nowhere has this trend been more necessary than digital cartography, of course, for all the aforementioned reasons. Three things set Google Maps apart from what came before: a clean and responsive user interface; fastloading, pre-generated map images; and a client-side API that makes it possible to put a Google Map on any web page. Of these three things, it might not be exaggerating to say that the openly published API behind Google Maps is far and away the most revolutionary of them all.

Who Will Aggregate the Aggregators?

A new approach to building web applications using Asynchronous JavaScript + XML (AJAX) has made this much easier. The AJAX approach employed by Google Maps and many other sites means that the web page is running code that dynamically fetches data as needed from a server, and that this data is usually in XML. “Yeah? So what?” you might say. Well, the “so what” is that these data sources are probably open and available for you to scrape. Sometimes they are published, and other times they are hidden in a page, but they are there.

A lot of new tech is established when developers have something that they can hack on. The Web has shown that the definition of developer is pretty wide! The original Web took off in large part because of the menu item View Source. Suddenly the barrier to entry was nearly microscopic. It was a shock when my own mother asked me for advice on web-authoring software, but that is what happens when you give people access to the tools that they can use to tell compelling stories. Google Maps, AJAX-based apps, and Web 2.0 remixing in general are similarly benefiting from the “View Source” mentality: others can look at your page, learn from your code, figure out where your data lives, and then remix it to make something greater.

The consequence is that Paul Rademacher can scrape data published in an open format by Craigslist and then put it on a map using an API openly published by Google. But what’s to keep you from scraping Paul’s site and a dozen others and putting that data on a map? To paraphrase Juvenal, who can live in our modern age and not write aggregators?

Not Just Where 2.0, But Also Why 2.0

Some people say “why should we give all our hard work to our competitors?” And you know, I’m not sure I have an answer for them. But I’ve noticed that most of the people and companies that ask that question are, well, boring or lame, while the coolest people and companies—and you probably know who I’m talking about—tend to be those that don’t ask that question. Though sometimes good people and good ideas are stuck in environments where secrecy is key, more often it’s as Rob Flickenger once said about the then-new copy-protected CD from Celine Dion that would not play on a computer: “Good! They are most of the way there. Now if they can only make a CD of Celine Dion that can’t play in any CD player….”

Let’s look a little bit deeper into this, though: maybe what makes the “open” camp seem interesting is that openness creates a space for interaction, and many interactions allow complex ecologies to form. Just as one example, we should point out that, thanks to Google’s approach of offering open access to their mapping service, there is already at least one software development outfit on the Web that advertises Google Maps integration as its primary offering.

So why share your code? Why share your data? Ultimately, if there’s one lesson that’s emerging from the wild world of Web 2.0, it’s that sharing and openness make the world a richer and more interesting place to live. Doing so might not make you as much money—but it might make you more—and the world will be more fun if you share. Our friend Marc Powell says that companies are a lot like kindergartners, and sometimes you just have to smile and say “That is nice, Billy, and would you like to share the crayons now?”

Why Google Maps Hacks?

The term hacking has a bad reputation in the press, where it is used to refer to someone who breaks into systems or wreaks havoc with computers as their weapon. Among people who write code, though, the term hack refers to a “quick-and-dirty” solution to a problem, or a clever way to get something done. And the term hacker is taken very much as a compliment, referring to someone as being creative, having the technical chops to get things done. The Hacks series is an attempt to reclaim the word, document the good ways people are hacking, and pass the hacker ethic of creative participation on to the uninitiated. Seeing how others approach systems and problems is often the quickest way to learn about a new technology.

Maps are a strange combination of the extremely simple and the extremely complex. Most people are familiar with paper maps, but are only starting to explore the possibilities of electronic maps. With the advent of Google Maps, incredible opportunities have opened up that go well beyond the usual expectations of paper maps. Google Maps Hacks will show you these opportunities and how to take advantage of them.

How to Use This Book

You can read this book from cover to cover if you like, but for the most part, each hack stands on its own, so feel free to browse and jump to the different sections that interest you most. If there’s a prerequisite you need to know about, a cross-reference will guide you to the right hack. So, feel free to browse, flipping around to whatever sections interest you most.

How This Book Is Organized

The book is divided into seven chapters, organized by subject:

Chapter 1, You Are Here: Introducing Google Maps

An introduction to http://maps.google.com, how to look up locations, get driving directions, look at satellite pictures, share links to maps in emails and on web pages, generate links to maps from a spreadsheet, and use del.icio.us (http://del.icio.us) to keep up with developments.

Chapter 2, Introducing the Google Maps API

Google Maps makes it easy to put a map on your own web page. Learn how to put a map on your page, capture user clicks, create a slideshow connected with a map, create custom icons, and measure distances.

Chapter 3, Mashing Up Google Maps

Are you interested in something? Chances are that someone has put some aspect of it on a Google Map. Learn about a variety of mashups, from mapping the news, to seeing where criminals “work,” to weather maps, to answering the question: where is the International Space Station right now? You can also examine the blast radius of a nuclear explosion, find a place to live, or see what is roughly the size of Texas.

Chapter 4, On the Road with Google Maps

Maps and travel go together like gruel and chipped teeth. Find the cheapest gas near to you, load driving directions into your GPS to take with you, look at your GPS tracklogs, explore hiking trails, figure out why your cell phone doesn’t work at home, and even beat a traffic ticket.

Chapter 5, Google Maps in Words and Pictures

Pictures and maps are a natural fit. One of the great things about photos is that they are always taken somewhere. Learn how to geocode your photos on Flickr, set up a blog that knows about place, geocode literature, and examine the choices that go into which satellite images are included.

Chapter 6, API Tips and Tricks

You now know how to put a map on your own page; in the chapter, learn how to tweak and extend that map. Include a map within your map, overlay photographs and labels where you want them, and create a georeferencer to pin your own scanned or digital maps onto a Google Map.

Chapter 7, Extreme Google Maps Hacks

Push the boundaries! Use a clustering algorithm so that your own points fit properly on a map, create your own map tiles, connect to a database, use web standards to display other data (such as Landsat imagery) on your maps, and even figure out if your kids are likely to barf.

Conventions Used in This Book

The following is a list of the typographical conventions used in this book:

Italics

Used to indicate URLs, filenames, filename extensions, and directory/folder names. For example, a path in the filesystem appears as /Developer/Applications.

Constant width

Used to show code examples, the contents of files, console output, as well as the names of variables, commands, and other code excerpts.

Constant width bold

Used to highlight portions of code, typically new additions to old code.

Constant width italic

Used in code examples and tables to show sample text to be replaced with your own values.

Gray type

Used to indicate a cross-reference within the text.

You should pay special attention to notes set apart from the text with the following icons:

Tip

This is a tip, suggestion, or general note. It contains useful supplementary information about the topic at hand.

Warning

This is a warning or note of caution, often indicating that something might break if you’re not careful, possibly quite badly.

The thermometer icons, found next to each hack, indicate the relative complexity of the hack:

/> beginner /> moderate /> expert

Whenever possible, the hacks in this book are not platform-specific, which means you can use them on Linux, Macintosh, and Windows machines. However, some things are possible only on a particular platform.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Google Maps Hacks by Rich Gibson and Schuyler Erle. Copyright © 2006 O’Reilly Media, Inc., 0-596-10161-9.”

If you feel your use of code examples falls outside fair use or the permission given above, feel free to contact us at .

How to Contact Us

We have tested and verified the information in this book to the best of our ability, but you may find that features have changed (or even that we have made mistakes!). As a reader of this book, you can help us to improve future editions by sending us your feedback. Please let us know about any errors, inaccuracies, bugs, misleading or confusing statements, and typos that you find anywhere in this book.

Please also let us know what we can do to make this book more useful to you. We take your comments seriously and will try to incorporate reasonable suggestions into future editions. You can write to us at:

O’Reilly Media, Inc.
1005 Gravenstein Highway North
Sebastopol, CA 95472
(800) 998-9938 (in the U.S. or Canada)
(707) 829-0515 (international/local)
(707) 829-0104 (fax)

To ask technical questions or to comment on the book, send email to:

The web site for Google Maps Hacks lists examples, errata, and plans for future editions. You can find this page at:

http://www.oreilly.com/catalog/googlemapshks/

The authors maintain the Mapping Hacks web site, which is related to the latest in digital cartography on the Web. On their site, you can find more information about the topics explored in this book. The Mapping Hacks site can be found at:

http://www.mappinghacks.com/

For more information about this book and others, see the O’Reilly web site:

http://www.oreilly.com

Got a Hack?

To explore Hacks books online or to contribute a hack for future titles, visit:

http://hacks.oreilly.com

Safari Enabled

When you see a Safari® Enabled icon on the cover of your favorite technology book, that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-Books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

Get Google Maps Hacks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.