What's New in Google Maps 2?

May 23, 2006
Share

Sharing is Caring

In my article titled Introduction to Developing with Google Maps, published in Directions Magazine on March 13, I introduced the fundamental programming constructs provided by the Google Maps API for building dynamic Web mapping applications. Since that time, Google has released Version 2 of its highly popular Google Maps API. As with any new software release, Version 2 of the Google Maps API provides a number of new and exciting changes to its Web mapping capabilities. Some of the most exciting additions to the API include the ability to add an overview map and tabbed Info Windows, the addition of a debugging window, and some fundamental changes to the programming constructs. I'll cover most of the new features of Version 2 of the Google Maps API in this article.

New GMap2 Object
Version 2 of the Google Maps API is designed to be backwards-compatible with the previous version of the API. What this means in practical terms is that the GMap object (for more information on the GMap object see the Introduction article) can still be used with Version 2. Like the original GMap class, the newly released GMap2 class enables you to create a map. You can create as many map instances as necessary for your application although most commonly this will only be a single instance. Maps are normally embedded within an HTML container called a
tag. The size of the map will default to the size specified in your
tag. Once you've generated an instance of GMap2 you can use the various methods and properties available on this object to manipulate other aspects of the map such as the controls included, the display of points of interest or polylines, and many other things. Everything in Google Maps flows through an instance of the GMap2 class.

GMap2 can also respond to a whole host of events. Events are simply an external stimulus to the map triggered by the user. Typical events might include the user dragging the map or clicking the map, an overlay marker added to the map, or the map type changing from normal to aerial. You can write code that responds to any of these and other events. For instance, you might want to add a marker at the point where the user clicks the map, or perhaps you could display the latitude/longitude coordinates of the center of the map following a pan event.

New Features in Version 2
This latest release of the Google Maps API includes a number of new features. In this section we'll cover these features in more detail.

Overview Map Control (GOverviewMapControl). Let's start with what is probably the most talked about new feature in Version 2: the Overview Map Control. The Overview Map Control adds a collapsible overview map to the bottom, right corner of the screen and displays the geographic extent of the main map with a blue rectangle. The extent of the main map can be controlled by dragging the rectangular extent in the overview map. Doing so will automatically change the current extent in the main map. Take a look at Figure 1 for an example of the Overview Map Control.
Figure 1: GOverviewMapControl. (Click for larger image)

Tabbed Info Windows. Another exciting addition to the API is the ability to create tabbed Info Windows similar to what you see in Figure 2. The openInfoWindowTabsHtml( ) method gives you the ability to create this special type of Info Window and is used in conjunction with the GInfoWindowTab class. The openInfoWindowTabsHtml( ) method is supplied with an array of GInfoWindowTab objects that specify the tab name and HTML that will be included on each tab.

Figure 2: New Tabbed Info Window. (Click for larger image)

Debugging Window. In Version 2, the Google Maps API provides a new GLog namespace that contains some static methods that allow you to write log messages to a log window similar to what you see in Figure 3. This enables basic debugging of your code through the ability to write debug messages. The first call to a GLog method opens a
(called the log window here) anchored to the lower left corner of the browser window. At the top of the log window is a title bar with two action links. The clear link will erase all messages from the log windows. The close link will close the log window.

Figure 3: GLog Window. (Click for larger image)

Smaller JavaScript Download. The new Google Maps API JavaScript file is about half the size of the old JavaScript file, which should improve the performance of your Web application.

Two Additional Satellite Zoom Levels. And increased imagery resolution and coverage in the U.S., Canada, U.K., Japan and Europe and almost every major city in the world.

Custom Map Controls.
You can define subclasses of GControl to define custom map controls in addition to the built-in controls like GSmallMapControl. Example here.

Custom Map Overlays. Typically you will add user data to your applications through the built-in GMarker and GPolyline classes. However, with the new Version you can define subclasses of GOverlay to create custom map overlays. Example here.

Fewer Memory Leaks. The API now includes a GUnload( ) method that you can call in the unload event of your page to destroy most circular references, including those formed implicitly during event registration. On Google Maps, this has virtually eliminated memory leaks in IE.

Other Significant Changes

GLatLng Replaces GPoint
Prior to Version 2 of the Google Maps API, the GPoint class was used to represent a single, two-dimensional longitude/latitude point of interest somewhere on the face of the earth. However, with Version 2, geographic coordinates are now represented by a new class: GLatLng. GPont now represents a point on a map by its pixel coordinates. This is a significant change that will need to be incorporated by existing Google Maps Version 1 sites and will necessitate changes to those applications.

GLatLng is normally used for two different yet important functions in Google Maps. The first reason for using GLatLng is to set the center point of your map. GLatLng is also used in conjunction with GMarker to create points of interest that are displayed as markers on your map. GMarker must have a coordinate defined by GLatLng to know where to place itself on the map.

Map Type Name Changes
The Map types (Map, Satellite, Hybrid) have new names in Version 2 of the API:
  • G_NORMAL_MAP
  • G_SATELLITE_MAP
  • G_HYBRID_MAP
Zoom Level Order
Zoom level indices in GMap2 start with 0 at the coarsest level, not at the finest level, which was the case in GMap. This allows for maps of arbitrarily high resolution, which allows Google to more easily introduce high resolution imagery. Conversion between old and new zoom level can be accomplished with the following formula:

newZoom = 17 oldZoom

Method Name Changes

On GMap2, new methods have replaced many of the GMap methods. Most of these changes involve the use of the GLatLng class. For more information on the many method changes, refer to the Google upgrade documentation.

Plug: For more comprehensive information on the Google Maps API please see our Google Maps For Your Apps! virtual training course ($75) or our new PDF book, Google Maps API: The New World of Web Mapping ($12.99 on its own, or free with the course).
Share

Sharing is Caring


Geospatial Newsletters

Keep up to date with the latest geospatial trends!

Sign up

Search DM

Get Directions Magazine delivered to you
Please enter a valid email address
Please let us know that you're not a robot by using reCAPTCHA.
Sorry, there was a problem submitting your sign up request. Please try again or email editors@directionsmag.com

Thank You! We'll email you to verify your address.

In order to complete the subscription process, simply check your inbox and click on the link in the email we have just sent you. If it is not there, please check your junk mail folder.

Thank you!

It looks like you're already subscribed.

If you still experience difficulties subscribing to our newsletters, please contact us at editors@directionsmag.com