Hacks 1016: Introduction

Table of contents:

Hacks 1016 Introduction

The Google Maps site at http://maps.google.com is awesome, with an easy user interface, one-box searching, and integrated satellite imagery. But it gets better! The Google Maps team has made it possible to include Google Maps with almost all of its great features onto your own web pages. They have done this by providing an open Application Program Interface, or API.

An API defines a standard way for one program to call code that lives within another application or library. The Google API defines a set of JavaScript objects and methods that you use to put maps on your own web pages.

Before Google Maps, it was much harder to put simple maps on your own pages. MapQuest had a program that let you create a link to a map. You could not embed the map on your own page, you could not put it into a frame, you couldn't even use Target=_new to open a new browser window.

There wereand areopen source solutions to generate maps. For example, the UMN Mapserver (http://mapserver.gis.umn.edu) is very powerful, allowing you to do things that Google Maps cannot yet equal, but there is a rather steep learning cliff. There are also industry standards for web mapping promulgated by the Open Geospatial Consortium (OGC) at http://www.opengeospatial.org.

The OGC-defined Web Mapping Service (WMS) and Web Feature Service (WFS) standards define a powerful web services interface to geospatial data. There are now free and easy-to-use open source clients for WMS and WFS data. For example, you can use the open source JavaScript library from http://openlayers.org/ to access public data sources and put free maps on your page.

These are great options that either were not available or were not easy to use when the Google Maps API was released. Some folks argue that Google did nothing new. There was free data out there, and there were web-enabled GIS systems. But clearly Google did something.

Creating feature-complete interfaces to geographic data that are so complex as to be inpenetrable by all but the highest of high priests seems to be nearly inevitable. Programmers start with a simple model, and then the world, the data, and the weight of history intrude to "complexify" our models and break our metaphors. When Walt Kelly wrote "We have met the enemy and he is us," he could have been describing the creators of most geospatial apps.

Somehow Google avoided that trap. As GPSBabel author Robert Lipe says, "We've seen an explosion in applications using the API. It's easy enough that you don't really need to be either a geo-geek, a cartographer, or a progamming jock to produce some really usable results."

Google has provided a readable introduction to the API, available at http://www.google.com/apis/maps/. They have created a "Hello World" of Google Maps that embeds a Google Map on a web page:


 

Google Maps JavaScript API Example - simple

You need a bit of glue in the form of the above div element and the script src= line, but there are only two important lines of code required to create and display a map centered on a specific point. The key code in this example creates a new GMap object and then centers the map on a specific point:

	var map = new GMap(document.getElementById("map"));
	map.centerAndZoom(new GPoint(-122.141944, 37.441944), 4);

 

In programming terms, the first line creates a new variable that contains a new GMap object. The GMap object will be linked with the section of the page marked with

. The second line then calls the centerAndZoom method of the GMap class.

The GMap class represents a single map on your page (yes, you can have multiple maps on the same page, each displaying a unique view).

There are other classes that provide additional features, such as GPoint to define a point and GPolyLine to define a line (there is not yet true polygon support), as well as a built-in XML parser and XSLT processor. Take a look at the API documentation at http://www.google.com/apis/maps/documentation.


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



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

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