Search Google Code

Google Maps API Version 2 Upgrade Guide

This documentation describes how to upgrade from Version 1 of the Google Maps API to Version 2, launched on April 3, 2006. If you developed your site before April 3, 2006, you should follow the instructions in this document to update your site to use the most recent version of the API.

Table of Contents

Introduction

Upgrade Overview

Version 2 of the Maps API is designed to be 99% backwards-compatible with the previous version of the API. Version 2 introduces a new map class, GMap2, that contains an updated interface with new method names. The old map class, GMap, will continue to exist in Version 2 of the API and contains the same ocumented interface as Version 1 of the API. However, most of the new features introduced in Version 2 of the API only work with the new GMap2 Map interface.

Given this design, you have two upgrade paths:

We did not preserve many of the undocumented functions between Version 1 and 2 of the API. We expect that this will be the biggest source of frustration for sites upgrading to this new version of the API.

Who Needs to Upgrade?

Every Maps API site should upgrade. Version 2 contains many important enhancements to fundamental parts of the Maps API, and Version 1 will be turned off once most sites have successfully upgraded.

Version 1 and Version 2 will coexist for at least one month no matter how few bugs are reported, and we may preserve Version 1 of the API for longer if people report many or complex transition problems. At that time, Version 2 will become the "default," and all sites will automatically start using it. Please report your problems to the Google Maps API discussion group, which our support staff actively moderates.

Incompatibilities Between Version 1 and Version 2

There are small number of incompatibilities between the documented features of Version 1 and Version 2, including:

Upgrading from GMap to GMap2

The GLatLng Class

Geographical coordinates and pixel coordinates are now expressed as separate classes, GLatLng and GPoint. Methods like setCenter now take in instances of GLatLng instead of instances of GPoint, so many of your method calls will have to be updated to reflect this when you upgrade to GMap2.

Version 2 also introduces the GLatLngBounds class, which properly respects the international date line.

See the class reference for more information.

Zoom Level Order

Zoom level indices in GMap2 start with 0 at the coarsest level, not at the finest. This allows maps of arbitrarily high resolution, which will let us more easily introduce high resolution imagery. You can convert between old and new zoom levels with the following formula:

newZoom = 17 - oldZoom

Map Type Name Changes

The Map types (Map, Satellite, Hybrid) have new names in Version 2 of the API:

Method Name Changes

Many of the methods in the GMap interface have been replaced with new methods that use the GLatLng class and are more consistent with our new, extensible GMap2 interface. You can update your constructor calls, method invocations, and event handler based on the table below:

Type Version 1
Version 2
constructor GMap(container, mapTypes?, width?, height?)
GMap2(container, opts?)
method GMap.getCenterLatLng()
GMap2.getCenter()
method GMap.getBoundsLatLng()
GMap2.getBounds()
method GMap.getSpanLatLng()
GMap2.getBounds()
method GMap.getZoomLevel()
GMap2.getZoom()
method GMap.centerAtLatLng(center)
GMap2.setCenter(center, zoom?, type?)
method GMap.centerAndZoom(center, zoom)
GMap2.setCenter(center, zoom?, type?)
method GMap.recenterOrPanToLatLng(center)
GMap2.panTo(center)
method GMap.zoomTo(level)
GMap2.setZoom(level)
method GMap.openInfoWindow(point, node, offset?, onopen?, onclose?)
GMap2.openInfoWindow(point, node, opts?)
method GMap.openInfoWindowHtml(point, html, offset?, onopen?, onclose?)
GMap2.openInfoWindowHtml(point, html, opts?)
method GMap.openInfoWindowXslt(point, node, xslturi, offset? , onopen?, onclose?)
-
method GMap.showMapBlowup(point, node, offset?, onopen?, onclose?)
GMap2.showMapBlowup(point, opts?)
event GMap.click(overlay, point)
GMap2.click(overlay, point)
event GMap.zoom(oldLevel, newLevel)
GMap2.zoomend(oldLevel, newLevel)
constructor GMarker(point, icon?)
GMarker(point, icon?, inert?)
method GMarker.openInfoWindow(content)
GMarker.openInfoWindow(content, opts?)
method GMarker.openInfoWindowHtml(content)
GMarker.openInfoWindowHtml(content, opts?)
method GMarker.openInfoWindowXslt(xml, xslt)
-
method GMarker.showMapBlowup(zoom?, type?)
GMarker.showMapBlowup(opts?)
constructor GPolyline(points, color?, weight?, opacity?)
GPolyline(points, color?, weight?, opacity?)
constructor GIcon(copy?)
GIcon(copy?, image?)
constructor GBounds(minx, miny, maxx, maxy)
GBounds(points)
constant G_MAP_TYPE
G_NORMAL_MAP
constant G_SATELLITE_TYPE
G_SATELLITE_MAP
constant G_HYBRID_TYPE
G_HYBRID_MAP
static method GXml.parse(xmltext)
GXml.parse(xmltext)
method GXslt.transformToHtml(xmlnode, htmlnode)
GXslt.transformToHtml(xmlnode, htmlnode)

New Features in Version 2

Version 2 of the Maps API introduces a number of new features, including: