My favorites | English | Sign in

Faster JavaScript with Closure Tools New!

Google Mapplets

Google Mapplets Reference

class GMap2

Instantiate class GMap2 in order to create a map. This is the central class in the API. Everything else is auxiliary.

Constructor

Constructor Description
GMap2() Returns a handle to the main map.

Asynchronous Methods

Configuration

Asynchronous Methods Callback Value Description
draggingEnabledAsync(callback) Boolean Returns true iff the dragging of the map is enabled.
infoWindowEnabledAsync(callback) Boolean Returns true iff the info window is enabled.
doubleClickZoomEnabledAsync(callback) Boolean Returns true iff double click to zoom is enabled.
continuousZoomEnabledAsync(callback) Boolean Returns true if continuous smooth zooming is enabled.

Map Types

Asynchronous Methods Callback Value Description
getMapTypesAsync(callback) Array of GMapType Returns the array of map types registered with this map.
getCurrentMapTypeAsync(callback) GMapType Returns the currently selected map type.
setMapType(type) none Selects the given new map type. The type must be known to the map. See the constructor, and the method addMapType().

Map State

Asynchronous Methods Callback Value Description
isLoadedAsync(callback) Boolean Returns true iff the map was initialized by setCenter() since it was created.
getCenterAsync(callback) GLatLng Returns the geographical coordinates of the center point of the map view.
getBoundsAsync(callback) GLatLngBounds Returns the the visible rectangular region of the map view in geographical coordinates.
getBoundsZoomLevelAsync(bounds, callback) Number Returns the zoom level at which the given rectangular region fits in the map view. The zoom level is computed for the currently selected map type. If no map type is selected yet, the first on the list of map types is used.
getSizeAsync(callback) GSize Returns the size of the map view in pixels.
getZoomAsync(callback) Number Returns the current zoom level.

Modify the Map State

Asynchronous Methods Callback Value Description
setCenter(center, zoom?, type?) none Sets the map view to the given center. Optionally, also sets zoom level and map type. The map type must be known to the map. See the constructor, and the method addMapType(). This method must be called first after construction to set the initial state of the map. It is an error to call other operations on the map after construction.
panTo(center) none Changes the center point of the map to the given point. If the point is already visible in the current map view, change the center in a smooth animation.
panBy(distance) none Starts a pan animation by the given distance in pixels.
panDirection(dx, dy) none Starts a pan animation by half the width of the map in the indicated directions. +1 is right and down, -1 is left and up, respectively.
setZoom(level) none Sets the zoom level to the given new value.
zoomIn() none Increments zoom level by one.
zoomOut() none Decrements zoom level by one.

Overlays

Asynchronous Methods Callback Value Description
addOverlay(overlay) none Adds an overlay to the map and fires the addoverlay event.
removeOverlay(overlay) none Removes the overlay from the map. If the overlay was on the map, it fires the removeoverlay event.
clearOverlays() none Removes all overlay from the map, and fires the clearoverlays event.

Info Window

Asynchronous Methods Callback Value Description
openInfoWindow(point, node, opts?) none Opens a simple info window at the given point. Pans the map such that the opened info window is fully visible. The content of the info window is given as a DOM node.
openInfoWindowHtml(point, html, opts?) none Opens a simple info window at the given point. Pans the map such that the opened info window is fully visible. The content of the info window is given as HTML text.
openInfoWindowTabs(point, tabs, opts?) none Opens a tabbed info window at the given point. Pans the map such that the opened info window is fully visible. The content of the info window is given as DOM nodes.
openInfoWindowTabsHtml(point, tabs, opts?) none Opens a tabbed info window at the given point. Pans the map such that the opened info window is fully visible. The content of the info window is given as HTML text.
showMapBlowup(point, opts?) none Opens an info window at the given point that contains a closeup view on the map around this point.
closeInfoWindow() none Closes the currently open info window.
getInfoWindowAsync(callback) GInfoWindow Returns the info window object of this map. If no info window exists yet, it is created, but not displayed. This operation is not influenced by enableInfoWindow().

Coordinate Transformations

Asynchronous Methods Callback Value Description
fromLatLngToDivPixelAsync(latlng, callback) GPoint Computes the pixel coordinates of the given geographical point in the DOM element that holds the draggable map. You need this method to position a custom overlay when you implement the GOverlay.redraw() method for a custom overlay.
fromDivPixelToLatLngAsync(pixel, callback) GLatLng Computes the geographical coordinates from pixel coordinates in the div that holds the draggable map. You need this when you implement interaction with custom overlays.
fromContainerPixelToLatLngAsync(pixel, callback) GLatLng Computes the geographical coordinates of the point at the given pixel coordinates in the DOM element that contains the map on the page. You need this when you implement interaction of custom controls with the map.

Events

Events Arguments Description
addmaptype type This event is fired when a map type is added to the map.
removemaptype type This event is fired when a map type is removed from the map.
click overlay, point This event is fired when the map is clicked with the mouse. If the click was on a marker, then the marker is passed to the event handler in the overlay argument, and a click event is also fired on the marker. Otherwise, the geographical coordinates of the point that was clicked are passed in the point argument.
dblclick overlay, point This event is fired when a double click is done on the map. Notice that this event will not be fired if the double click was on a marker. The geographical coordinates of the point that was double clicked are passed in the point argument. The overlay argument is always set to null.
movestart none This event is fired when the map view starts changing. This can be caused by dragging, in which case a dragstart event is also fired, or by invocation of a method that changes the map view.
moveend none This event is fired when the change of the map view ends.
zoomend oldLevel, newLevel This event is fired when the map reaches a new zoom level. The event handler receives the previous and the new zoom level as arguments.
maptypechanged none This event is fired when another map type is selected.
infowindowopen none This event is fired when the info window opens.
infowindowclose none This event is fired when the info window closes. The event infowindowbeforeclose is fired before this event. If a currently open info window is reopened at a different point using another call to openInfoWindow*(), the events infowindowbeforeclose, infowindowclose and infowindowopen are fired in this order.
addoverlay overlay This event is fired when a single overlay is added to the map by the method addOverlay(). The new overlay is passed as an argument overlay to the event handler.
removeoverlay overlay This event is fired when a single overlay is removed by the method removeOverlay(). The overlay that was removed is passed as an argument overlay to the event handler.
clearoverlays none This event is fired when all overlays are removed at once by the method clearOverlays().
dragstart none This event is fired when the user starts dragging the map.
dragend none This event is fired when the user stops dragging the map.

class GInfoWindow

GInfoWindow has no constructor. It is created by the map and accessed by its method GMap2.getInfoWindowAsync(callback: Function).

Asynchronous Methods

Asynchronous Methods Callback Value Description
selectTab(index) none Selects the tab with the given index. This has the same effect as clicking on the corresponding tab.
hide() none Makes the info window invisible. NOTE: This doesn't close the info window. It can be made visible again using show().
show() none Makes the info window visible if it's currently invisible.
isHiddenAsync() Boolean Returns true iff the info window is hidden. A closed info window is considered hidden.
reset(point, tabs, size, offset?, selectedTab?) none Resets the state of the info window. Each argument may be null and then its value will not be changed from the current value.
getPointAsync() GLatLng Returns the geographical point at which the info window is anchored. The tip of the window points to this point on the map, modulo the pixel offset.
getPixelOffsetAsync() GSize Returns the offset, in pixels, of the tip of the info window from the point on the map at whose geographical coordinates the info window is anchored.
getSelectedTabAsync() Number Returns the index, starting at 0, of the current selected tab.

Events

Events Arguments Description
closeclick none This event is fired when the info window close button is clicked. An event handler for this event can implement to close the info window, by calling the GMap2.closeInfoWindow() method.

class GInfoWindowTab

An array of instances of this class can be passed as the tabs argument to the methods GMap2.openInfoWindowTabs(), GMap2.openInfoWindowTabsHtml(), GMarker.openInfoWindowTabs(), GMarker.openInfoWindowTabsHtml() and the bindInfoWindow*() variants. If the array contains more than one element, the info window will be shown with tabs. Every InfoWindowTab object contains two items: content defines the content of the info window when the tab is selected, and label defines the label of the tab. The properties are passed as arguments to the constructor. For the openInfoWindowTabs() methods, content is a DOM Node. For the methods openInfoWindowTabsHtml(), content is a string that contains HTML text.

Constructor

Constructor Description
GInfoWindowTab(label, content) Creates an info window tab data structure that can be passed in the tabs argument to openInfoWindowTabs*() methods.

class GInfoWindowOptions

Instances of this class are used in the opts? argument to the methods openInfoWindow(), openInfoWindowHtml(), openInfoWindowTabs(), openInfoWindowTabsHtml(), bindInfoWindow*() and showMapBlowup() of classes GMap2 and GMarker. There is no constructor for this class. Instead, this class is instantiated as javascript object literal.

Properties

As the name of this class indicates, all properties are optional.

Properties Type Description
disableGoogleLinks Boolean Suppress the the Google links for driving directions and local search that are automatically appended onto the bottom of info windows.
selectedTab Number Selects the tab with the given index, starting at 0, instead of the first tab (with index 0).
maxWidth Number Maximum width of the info window content, in pixels.
zoomLevel Number Pertinent for showMapBlowup() only. The zoom level of the blowup map in the info window.
mapType GMapType Pertinent for showMapBlowup() only. The map type of the blowup map in the info window.

class GMarker

A GMarker marks a position on the map. It implements the GOverlay interface and thus is added to the map using the GMap2.addOverlay() method.

A marker object has a point, which is the geographical position where the marker is anchored on the map, and an icon. If the icon is not set in the constructor, the default icon G_DEFAULT_ICON is used.

After it is added to a map, the info window of that map can be opened through the marker. The marker object will fire mouse events and infowindow events.

Constructor

Constructor Description
GMarker(point, icon?, inert?) Creates a marker at the passed point of either GPoint or GLatLng with icon or the G_DEFAULT_ICON. If the inert flag is true, then the marker is not clickable and will not fire any events.
GMarker(latlng, opts?) Creates a marker at the latlng with options specified in GMarkerOptions.

Asynchronous Methods

Before these methods can be invoked, the marker must be added to a map.

Asynchronous Methods Callback Value Description
openInfoWindow(content, opts?) none Opens the map info window over the icon of the marker. The content of the info window is given as a DOM node. Only option GInfoWindowOptions.maxWidth is applicable.
openInfoWindowHtml(content, opts?) none Opens the map info window over the icon of the marker. The content of the info window is given as a string that contains HTML text. Only option GInfoWindowOptions.maxWidth is applicable.
openInfoWindowTabs(tabs, opts?) none Opens the tabbed map info window over the icon of the marker. The content of the info window is given as an array of tabs that contain the tab content as DOM nodes. Only options GInfoWindowOptions.maxWidth and InfoWindowOptions.selectedTab are applicable.
openInfoWindowTabsHtml(tabs, opts?) none Opens the tabbed map info window over the icon of the marker. The content of the info window is given as an array of tabs that contain the tab content as Strings that contain HTML text. Only options InfoWindowOptions.maxWidth and InfoWindowOptions.selectedTab are applicable.
bindInfoWindow(content, opts?) none Binds the given DOM node to this marker. This content will be automatically displayed in the info window when the marker is clicked. Pass content as null to unbind.
bindInfoWindowHtml(content, opts?) none Binds the given html to this marker. This content will be automatically displayed in the info window when the marker is clicked. Pass content as null to unbind.
bindInfoWindowTabs(tabs, opts?) none Binds the given tabs to this marker. This content will be automatically displayed in the info window when the marker is clicked. Pass content as null to unbind.
bindInfoWindowTabsHtml(tabs, opts?) none Binds the given tabs to this marker. This content will be automatically displayed in the info window when the marker is clicked. Pass content as null to unbind.
closeInfoWindow() none Closes the info window only if it belongs to this marker.
showMapBlowup(opts?) none Opens the map info window over the icon of the marker. The content of the info window is a closeup map around the marker position. Only options InfoWindowOptions.zoomLevel and InfoWindowOptions.mapType are applicable.
getIconAsync(callback) GIcon Returns the icon of this marker, as set by the constructor.
getPointAsync(callback) GLatLng Returns the geographical coordinates of the point at which this marker is anchored, as set by the constructor or by setPoint().
setPoint(point) none Sets the geographical coordinates of the point at which this marker is anchored.
enableDragging() none Enables the marker to be dragged and dropped around the map. To function, the marker must have been initialized with GMarkerOptions.draggable = true.
disableDragging() none Disables the marker from being dragged and dropped around the map.
draggableAsync(callback) Boolean Returns true if the marker is draggable.
draggingEnabledAsync(callback) Boolean Returns true if dragging is enabled for the marker.
setImage(url) none Requests the image specified by the url to be set as the foreground image for this marker. Please note that neither the print image nor the shadow image are adjusted. Therefore this method is primarily intended to implement highlighting or dimming effects, rather than drastic changes in marker's appearances.
hide() none Hides the marker if it is currently visible. Please note that this function triggers the event GMarker.visibilitychanged in case the marker is currently visible.
show() none Shows the marker if it is currently hidden. Please note that this function triggers the event GMarker.visibilitychanged in case the marker is currently hidden.
isHiddenAsync(callback) Boolean Returns true if the marker is currently hidden. Otherwise returns false.

Events

All these events fire only if the marker is not inert (see constructor).

Events Arguments Description
click none This event is fired when the marker icon was clicked. Notice that this event will also fire for the map, with the marker passed as the first argument to the event handler there.
dblclick none This event is fired when the marker icon was double-clicked. Notice that this event will not fire for the map, because the map centers on double-click as a hardwired behavior.
infowindowopen none This event is fired when the info window of the map was opened through this marker.
infowindowclose none This event is fired when the info window of the map that was opened through this marker is closed. This happens when either the info window was closed, or when it was opened on another marker, or on the map. The event infowindowbeforeclose is fired before this event.
remove none This event is fired when the marker is removed from the map, using GMap2.removeOverlay() or GMap2.clearOverlays().
dragstart none If the marker is enabled for dragging, this event is fired when the marker dragging begins.
dragend none If the marker is enabled for dragging, this event is fired when the marker ceases to be dragged.
visibilitychanged isVisible This event is fired when the visibility of the marker is changed (i.e. the visibility is flipped from visible to hidden or vice-versa). isVisible refers to the state of the marker after the visibility change has happened.

class GMarkerOptions

Instances of this class are used in the opts? argument to the constructor of the GMarker class. There is no constructor for this class. Instead, this class is instantiated as a javascript object literal.

Properties

As the name of this class indicates, all properties are optional.

Properties Type Description
icon GIcon Chooses the Icon for this class. If not specified, G_DEFAULT_ICON is used.
dragCrossMove Boolean When dragging markers normally, the marker floats up and away from the cursor. Setting this value to true keeps the marker underneath the cursor, and moves the cross downwards instead. The default value for this option is false.
title String This string will appear as tooltip on the marker, i.e. it will work just as the title attribute on HTML elements.
clickable Boolean Toggles whether or not the marker is clickable. Markers that are not clickable or draggable are inert, consume less resources and do not respond to any events. The default value for this option is true, i.e. if the option is not specified, the marker will be clickable.
draggable Boolean Toggles whether or not the marker will be draggable by users. Markers set up to be dragged require more resources to set up than markers that are clickable. Any marker that is draggable is also clickable and bouncy by default. The default value for this option is false.
bouncy Boolean Toggles whether or not the marker should bounce up and down after it finishes dragging. The default value for this option is false.
bounceGravity Number When finishing dragging, this number is used to define the acceleration rate of the marker during the bounce down to earth. The default value for this option is 1.

class GPolyline

This is a map overlay that draws a polyline on the map, using the vector drawing facilities of the browser if they are available, or an image overlay from Google servers otherwise.

Constructor

Constructor Description
GPolyline(points, color?, weight?, opacity?, opts?) Creates a polyline from an array of vertices. The color is given as a string that contains the color in hexadecimal numeric HTML style, i.e. #RRGGBB. The weight is the width of the line in pixels. The opacity is given as a number between 0 and 1. The line will be antialiased and semitransparent.

Asynchronous Methods

Asynchronous Methods Callback Value Description
deleteVertex(index) none Removes the vertex with the given index in the polyline and updates the shape of the polyline accordingly. The GPolyline must already be added to the map via GMap2.addOverlay().
disableEditing() none Reverses the effects of enableEditing, removing all control points from the line and rendering it uneditable by the user. If the option onEvent is specified, editing will be disabled whenever that event is triggered on the polyline. For example, if onEvent = "mouseout", editing will be disabled whenever the mouse leaves the polyline.
enableDrawing(opts?) none Allows a user to construct (or modify) a GPolyline object by clicking on additional points on the map. The GPolyline must already be added to the map via GMap2.addOverlay(), even if the polyline is initially unpopulated and contains no vertices. Each click adds an additional vertex to the polyline chain, and drawing may be terminated through either a double-click or clicking again on the last point added, at which point an "endline" event will be triggered if the polyline was successfully completed; otherwise, a "cancelline" event will be triggered, but the polyline will not be removed from the map. If modifying an existing GPolyline, vertices are connected from either the starting or ending points of the existing polyline, specified in the optional GPolyEditingOptions.fromStart parameter.
enableEditing(opts?) none Allows modification of an existing GPolyline chain of points. When enabled, users may select and drag existing vertices. Unless a vertex limit less than current number of vertices is specified by maxVertices within GPolyEditingOptions, "ghost" points will also be added at the midpoints of polyline sections, allowing users to interpolate new vertices by clicking and dragging these additional vertices. A "lineupdated" event will be triggered whenever vertex is added or moved. If the option onEvent within GPolyEditingOptions is specified, editing will be enabled whenever that event is triggered on the polyline. For example, if onEvent = "mouseover", editing will be enabled whenever the mouse moves over the polyline.
getVertexCountAsync(callback) Number Returns the number of vertices in the polyline.
getVertexAsync(index, callback) GLatLng Returns the vertex with the given index in the polyline.
getLengthAsync(callback) Number Returns the length (in meters) of the polyline along the surface of a spherical Earth.
getBoundsAsync(callback) GLatLngBounds Returns the bounds for this polyline.
insertVertex(index, latlng) none Inserts a new point at the given index in the polyline and updates its shape. The GPolyline must already be added to the map via GMap2.addOverlay().
setStrokeStyle(style) none Changes the style of the polyline. The GPolyline must already be added to the map via GMap2.addOverlay().

Events

Events Arguments Description
remove none This event is fired when the polyline is removed from the map, using GMap2.removeOverlay() or GMap2.clearOverlays().
click none This event is fired when a user clicks on the polyline.
lineupdated none This event is fired when either the style or shape of the polyline is updated.
endline none This event is fired when line drawing (initiated by call to GPolyline.enableDrawing) is completed by the user.
cancelline none This event is fired when line drawing (initiated by call to GPolyline.enableDrawing) is aborted by the user.

class GPolylineOptions

Instances of this class are used in GPolyline's constructor. There is no constructor for this class. Instead, this class is instantiated as a javascript object literal.

Properties

As the name of this class indicates, all properties are optional.

Properties Type Description
geodesic Boolean Render each edge of the polyline as a geodesic. This is the shortest path between two points along a spherical Earth.

class GPolyEditingOptions

Instances of this class are used in the enableEditing methods of GPolyline and GPolygon. There is no constructor for this class. Instead, this class is instantiated as a javascript object literal.

Properties

As the name of this class indicates, all properties are optional.

Properties Type Description
maxVertices Number The maximum number of vertices permitted for this polyline. Once this number is reached, no more may be added.
fromStart Boolean Whether enableDrawing should add points from the start rather than from the end, which is the default.
onEvent String The name of an event on which to trigger enableEditing or disableEditing. If no event is specified, the action will occur unconditionally.

class GPolyStyleOptions

Instances of this class are used in the setStrokeStyle method of GPolyline and GPolygon and the setFillStyle method of GPolygon. There is no constructor for this class. Instead, this class is instantiated as a javascript object literal.

Properties

As the name of this class indicates, all properties are optional.

Properties Type Description
color String a string that contains a hexadecimal numeric HTML style, i.e. #RRGGBB.
weight Number the width of the line in pixels.
opacity Number a number between 0 and 1.

class GPolygon

This is very similar to a GPolyline, except that you can additionally specify a fill color and opacity.

Constructor

Constructor Description
GPolygon(points, strokeColor?, strokeWeight?, strokeOpacity?, fillColor?, fillOpacity?) Creates a polygon from an array of vertices. The colors are given as a string that contains the color in hexadecimal numeric HTML style, i.e. #RRGGBB. The weight is the width of the line in pixels. The opacities is given as a number between 0 and 1. The line will be antialiased and semitransparent.

Asynchronous Methods

Asynchronous Methods Callback Value Description
deleteVertex(index) none Removes with the given index in the polygon and updates the shape of the polygon accordingly. The GPolygon must already be added to the map via GMap2.addOverlay().
disableEditing() none Reverses the effects of enableEditing, removing all control points from the line and rendering it uneditable by the user. If the option onEvent is specified, editing will be disabled whenever that event is triggered on the polygon. For example, if onEvent = "mouseout", editing will be disabled whenever the mouse leaves the polygon.
enableDrawing(opts?) none Allows a user to construct a GPolygon object by clicking on additional points on the map. The GPolyline must already be added to the map via the GMap2.addOverlay(), even if the polyline is initially unpopulated and contains no vertices. Each click adds an additional vertex to the polygon boundary, and drawing may be terminated through either a double-click, or clicking on the first point to complete the shape, at which point an "endline" event will be triggered if the polygon was successfully completed; otherwise, a "cancelline" event will be triggered, but the polyline will not be removed from the map.
enableEditing(opts?) none Allows modification of an existing GPolygon boundary. When enabled, users may select and drag existing vertices. Unless a vertex limit less than current number of vertices is specified by maxVertices within GPolyEditingOptions, "ghost" points will also be added at the midpoints of polygon sections, allowing users to interpolate new vertices by clicking and dragging these additional vertices. A "lineupdated" event will be triggered whenever vertex is added or moved. If the option onEvent is specified within GPolyEditingOptions, editing will be enabled whenever that event is triggered on the polygon. For example, if onEvent = "mouseover", editing will be enabled whenever the mouse moves over the polygon.
getVertexCountAsync(callback) Number Returns the number of vertices in the polygon.
getVertexAsync(index, callback) GLatLng Returns the vertex with the given index in the polygon.
getAreaAsync(callback) Number Returns the area (in square meters) of the polygon, assuming a spherical Earth.
getBoundsAsync(callback) GLatLngBounds Returns the bounds for this polygon.
insertVertex(index, latlng) none Inserts a new point at the given index in the polygon. The GPolygon must already be added to the map via GMap2.addOverlay().
setFillStyle(style) none Changes the fill style of the polygon.
setStrokeStyle(style) none Changes the line style of the polygon.

Events

Events Arguments Description
remove none This event is fired when the polygon is removed from the map, using GMap2.removeOverlay() or GMap2.clearOverlays().
click none This event is fired when a user clicks on the polygon.
lineupdated none This event is fired when either the style or shape of the polygon is updated.
endline none This event is fired when polygon drawing (initiated by call to GPolyline.enableDrawing) is completed by the user.
cancelline none This event is fired when polygon drawing (initiated by call to GPolyline.enableDrawing) is aborted by the user.

class GGroundOverlay

This object creates a rectangular image overlay on the map, whose boundaries are defined by GLatLngBounds.

Constructor

Constructor Description
GGroundOverlay(imageUrl, bounds)

class GIcon

An icon specifies the images used to display a GMarker on the map. For browser compatibility reasons, specifying an icon is actually quite complex. Note that you can use the default Maps icon G_DEFAULT_ICON if you don't want to specify your own.

Constructor

Constructor Description
GIcon(copy?, image?) Creates a new icon object. If another icon is given in the optional copy argument, its properties are copied, otherwise they are left empty. The optional argument image sets the value of the image property.

Constants

Constants Description
G_DEFAULT_ICON The default icon used by markers.

Properties

Properties Type Description
image String The foreground image URL of the icon.
shadow String The shadow image URL of the icon.
iconSize GSize The pixel size of the foreground image of the icon.
shadowSize GSize The pixel size of the shadow image.
iconAnchor GPoint The pixel coordinate relative to the top left corner of the icon image at which this icon is anchored to the map.
infoWindowAnchor GPoint The pixel coordinate relative to the top left corner of the icon image at which the info window is anchored to this icon.
printImage String The URL of the foreground icon image used for printed maps. It must be the same size as the main icon image given by image.
mozPrintImage String The URL of the foreground icon image used for printed maps in Firefox/Mozilla. It must be the same size as the main icon image given by image.
printShadow String The URL of the shadow image used for printed maps. It should be a GIF image since most browsers cannot print PNG images.
transparent String The URL of a virtually transparent version of the foreground icon image used to capture click events in Internet Explorer. This image should be a 24-bit PNG version of the main icon image with 1% opacity, but the same shape and size as the main icon.
imageMap Array of Number An array of integers representing the x/y coordinates of the image map we should use to specify the clickable part of the icon image in browsers other than Internet Explorer.
maxHeight Integer Specifies the distance in pixels in which a marker will visually "rise" vertically when dragged.
dragCrossImage String Specifies the cross image URL when an icon is dragged.
dragCrossSize GSize Specifies the pixel size of the cross image when an icon is dragged.
dragCrossAnchor GPoint Specifies the pixel coordinate offsets (relative to the iconAnchor) of the cross image when an icon is dragged.

class GPoint

A GPoint represents a point on the map by its pixel coordinates. Notice that in v2, it doesn't represent a point on the earth by its geographical coordinates anymore. Geographical coordinates are now represented by GLatLng.

In the map coordinate system, the x coordinate increases to the left, and the y coordinate increases downwards.

Notice that while the two parameters of a GPoint are accessible as properties x and y, it is better to never modify them, but to create a new object with different paramaters instead.

Constructor

Constructor Description
GPoint(x, y) Creates a GPoint object.

Properties

Properties Type Description
x Number x coordinate, increases to the left.
y Number y coordinate, increases downwards.

Methods

Methods Return Value Description
equals(other) Boolean Returns true iff the other point has equal coordinates.
toString() String Returns a string that contains the x and y coordinates, in this order, separated by a comma.

class GSize

A GSize is the size in pixels of a rectangular area of the map. The size object has two parameters, width and height. Width is a difference in the x-coordinate; height is a difference in the y-coordinate, of points.

Notice that while the two parameters of a GSize are accessible as properties width and height, it is better to never modify them, but to create a new object with different paramaters instead.

Constructor

Constructor Description
GSize(width, height) Creates a GSize object.

Properties

Properties Type Description
width Number The width parameter.
height Number The height parameter.

Methods

Methods Return Value Description
equals(other) Boolean Returns true iff the other size has exactly equal components.
toString() String Returns a string that contains the wdith and height parameter, in this order, separated by a comma.

class GBounds

GBounds is a rectangular area of the map in pixel coordinates. Notice that a rectangle in geographical coordinates is represented by a GLatLngBounds object.

Constructor

Constructor Description
GBounds(points) Constructs a rectangle that contains all the given points.

Properties

Properties Type Description
minX Number The x coordinate of the left edge of the rectangle.
minY Number The y coordinate of the top edge of the rectangle.
maxX Number The x coordinate of the right edge of the rectangle.
maxY Number The y coordinate of the bottom edge of the rectangle.

Methods

Methods Return Value Description
toString() String Returns a string that contains the coordinates of the upper left and the lower right corner points of the box, in this order, separated by comma, surrounded by parentheses.
min() GPoint The point at the upper left corner of the box.
max() GPoint The point at the lower right corner of the box.
containsBounds(other) Boolean Returns true iff the other box is entirely contained in this box.
extend(point) none Enlarges this box so that the point is also contained in this box.
intersection(other) GBounds Returns the box by which this box overlaps the other box. If there is no overlap, returns an empty box.

class GLatLng

GLatLng is a point in geographical coordinates longitude and latitude.

Notice that although usual map projections associate longitude with the x-coordinate of the map, and latitude with the y-coordinate, the latitude cooridnate is always written first, followed by the longitude, as it is custom in cartography.

Notice also that you cannot modify the coordinates of a GLatLng. If you want to compute another point, you have to create a new one.

Constructor

Constructor Description
GLatLng(lat, lng, unbounded?) Notice the ordering of latitude and longitude. If the unbounded flag is true, then the numbers will be used as passed, oterwise latitude will be clamped to lie between -90 degrees and +90 degrees, and longitude will be wrapped to lie between -180 degrees and +180 degrees.

Methods

Methods Return Value Description
lat() Number Returns the latitude coordinate in degrees, as a number between -90 and +90. If the unbounded flag was set in the constructor, this coordinate can be outside this interval.
lng() Number Returns the longitude coordinate in degrees, as a number between -180 and +180. If the unbounded flag was set in the constructor, this coordinate can be outside this interval.
latRadians() Number Returns the latitude coordinate in radians, as a number between -PI/2 and +PI/2. If the unbounded flag was set in the constructor, this coordinate can be outside this interval.
lngRadians() Number Returns the longitude coordinate in radians, as a number between -PI and +PI. If the unbounded flag was set in the constructor, this coordinate can be outside this interval.
equals(other) Boolean Returns true iff the other size has equal components, within certain roundoff margins.
distanceFrom(other) Number Returns the distance, in meters, from this point to the given point. The earth is approximated as a sphere, hence the distance could be off by as much as 0.3%.
toUrlValue() String This version of the method has been deprecated in favor of the revised version (shown below) which passes an optional precision parameter.
toUrlValue(precision?) String Returns a string that represents this point in a format suitable for use as a URL parameter value, separated by a comma, without whitespace. By default, precision is returned to 6 digits, which corresponds to a resolution to 4 inches/ 11 centimeters. An optional precision parameter allows you to specify a lower precision to reduce server load. Note: prior to 2.78, this precision parameter was not available.

Properties

These properties exist for backwards compatibility with v1 event handler functions only. They should not be used.

These properties mirror the return values of the lng() and lat() accessor methods and they allow a GLatLng to appear in places where a GPoint is expected by a v1 client. This is necessary where GLatLng appears in event details (i.e. in arguments of event handler functions). In contrast to method wrappers, it is impossible in the current infrastructure to create event wrappers.

Properties Type Description
x Number Deprecated.
y Number Deprecated.

class GLatLngBounds

A GLatLngBounds instance represents a rectangle in geographical coordinates, including one that crosses the 180 degrees meridian.

Constructor

Constructor Description
GLatLngBounds(sw?, ne?) Constructs a rectangle from the points at its south-west and north-east corners.

Methods

Methods Return Value Description
equals(other) Boolean Returns true iff all parameters in this rectangle are equal to the parameters of the other, within a certain roundoff margin.
contains(latlng) Boolean Returns true iff the geographical coordinates of the point lie within this rectangle.
intersects(other) Boolean What the name says.
containsBounds(other) Boolean What the name says.
extend(latlng) none Enlarges this rectangle such that it contains the given point. In longitude direction, it is enlarged in the smaller of the two possible ways. If both are equal, it is enlarged at the eastern boundary.
getSouthWest() GLatLng Returns the point at the south-west corner of the rectangle.
getNorthEast() GLatLng Returns the point at the north-east corner of the rectangle.
toSpan() GLatLng Returns a GLatLng whose cordinates represent the size of this rectangle.
isFullLat() Boolean Returns true if this rectangle extends from the south pole to the north pole.
isFullLng() Boolean Returns true if this rectangle extends fully around the earth in the longitude direction.
isEmpty() Boolean Returns true if this rectangle is empty.
getCenter() GLatLng Returns the point at the center of the rectangle.

class GTileLayer

This class takes a tile url template that is expanded for each tile request. For example 'http://host/tile?x={X}&y={Y}&z={Z}.png', which will turn into eg. 'http://host/tile?x=3&y=27&z=5.png'. An alternative to the {Z} meaning 'zoom' is {V1_Z}, which stands for 'zoom using the Maps API version 1 naming convention', where 17 is zoomed all the way out (the world in one tile) and zoom 0 is street- level. Effectively, {V1_Z} = 17 - {Z}.

Constructor

Constructor Description
GTileLayer(null, minResolution, maxResolution, opts) opts.tileUrlTemplate must be a valid url template as described above.

class GTileLayerOverlay

A GTileLayerOverlay augments the map with a GTileLayer. It implements the GOverlay interface and thus is added to the map using the GMap2.addOverlay() method.

Constructor

Constructor Description
GTileLayerOverlay(tileLayer) Creates a GTileLayerOverlay that wraps the tileLayer.

Asynchronous Methods

Asynchronous Methods Callback Value Description
hide() none Hides this overlay so it is not visible, but maintains its position in the stack of overlays.
show() none Shows a previously hidden TileLayerOverlay.
getTileLayerAsync() none Returns the tile layer used by this overlay.

namespace GEvent

This namespace contains functions that you use to register event handlers, both for custom events and for DOM events, and to fire custom events. All the events defined by this API are custom events that are internally fired by GEvent.trigger().

Static Methods

Static Methods Return Value Description
addListener(source, event, handler) GEventListener Registers an event handler for a custom event on the source object. Returns a handle that can be used to eventually deregister the handler. The event handler will be called with this set to the source object.
addDomListener(source, event, handler) GEventListener Registers an event handler for a DOM event on the source object. The source object must be a DOM Node. Returns a handle that can be used to eventually deregister the handler. The event handler will be called with this set to the source object. This function uses the DOM methods for the current browser to register the event handler.
removeListener(handle) none Removes a handler that was installed using addListener() or addDomListener().
clearListeners(source, event) none Removes all handlers on the given object for the given event that were installed using addListener() or addDomListener().
clearInstanceListeners(source) none Removes all handlers on the given object for all events that were installed using addListener() or addDomListener().
trigger(source, event, ...) none Fires a custom event on the source object. All remaining optional arguments after event are passed in turn as arguments to the event handler functions.
bind(source, event, object, method) GEventListener Registers an invocation of the method on the given object as the event handler for a custom event on the source object. Returns a handle that can be used to eventually deregister the handler.
bindDom(source, event, object, method) GEventListener Registers an invocation of the method on the given object as the event handler for a custom event on the source object. Returns a handle that can be used to eventually deregister the handler.
callback(object, method) Function Returns a closure that calls method on object.
callbackArgs(object, method, ...) Function Returns a closure that calls method on object. All remaining optional arguments after method are passed in turn as arguments method when the returned function is invoked.

Events

Events Arguments Description
clearlisteners event? This event is fired on object when clearListeners() or clearInstanceListeners() is called on that object. Of course, the event is fired before the functions are executed.

class GEventListener

This class is opaque. It has no methods and no constructor. Its instances are returned from GEvent.addListener() or GEvent.addDomListener() and are eventually passed back to GEvent.removeListener().

enum GGeoStatusCode

Numeric equivalents for each symbolic constant are specified in parentheses.

Constants

Constants Description
G_GEO_SUCCESS (200) No errors occurred; the address was successfully parsed and its geocode has been returned.
G_GEO_BAD_REQUEST (400) A directions request could not be successfully parsed.
G_GEO_SERVER_ERROR (500) A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.
G_GEO_MISSING_QUERY (601) The HTTP q parameter was either missing or had no value. For geocoding requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.
G_GEO_MISSING_ADDRESS (601) Synonym for G_GEO_MISSING_QUERY.
G_GEO_UNKNOWN_ADDRESS (602) No corresponding geographic location could be found for the specified address. This may be due to the fact that the address is relatively new, or it may be incorrect.
G_GEO_UNAVAILABLE_ADDRESS (603) The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.
G_GEO_UNKNOWN_DIRECTIONS (604) The GDirections object could not compute directions between the points mentioned in the query. This is usually because there is no route available between the two points, or because we do not have data for routing in that region.
G_GEO_BAD_KEY (610) The given key is either invalid or does not match the domain for which it was given.

enum GGeoAddressAccuracy

There are no symbolic constants defined for this enumeration.

Constants

Constants Description
0 Unknown location.
1 Country level accuracy.
2 Region (state, province, prefecture, etc.) level accuracy.
3 Sub-region (county, municipality, etc.) level accuracy.
4 Town (city, village) level accuracy.
5 Post code (zip code) level accuracy.
6 Street level accuracy.
7 Intersection level accuracy.
8 Address level accuracy.

class GClientGeocoder

This class is used to communicate directly with Google servers to obtain geocodes for user specified addresses. In addition, a geocoder maintains its own cache of addresses, which allows repeated queries to be answered without a round trip to the server.

Constructor

Constructor Description
GClientGeocoder() Creates a new instance of a geocoder that talks directly to Google servers.

Asynchronous Methods

Asynchronous Methods Callback Value Description
getLatLngAsync(address, callback) GLatLng Sends a request to Google servers to geocode the specified address. If the address was successfully located, the user-specified callback function is invoked with a GLatLng point. Otherwise, the callback function is given a null point. In case of ambiguous addresses, only the point for the best match is passed to the callback function.
getLocationsAsync(address, callback) JSON Sends a request to Google servers to geocode the specified address. A reply that contains status code, and if successful, one or more Placemark objects, is passed to the user-specified callback function. Unlike the GClientGeocoder.getLatLng method, the callback function may determine the reasons for failure by examining the code value of the Status field.

class GGeoXml

A GGeoXml object add geographic content to the map from an XML file (such as a KML file) that is hosted on a publicly accessible web server. It implements the GOverlay interface and thus is added to the map using the GMap2.addOverlay() method.

Constructor

Constructor Description
GGeoXml(urlOfXml, opt_callback) Creates a GOverlay that represents that XML file. An optional callback function is invoked when the GGeoXml object finishes loading the XML file.

function GAsync

A utility function to make multiple asynchronous requests in parallel. It collects the results and passes them to a single callback that you provide. For example, to get the current zoom level of map, perform a coordinate transformation for point, and get the position of marker:

GAsync( map, 'getZoom', 'fromContainerPixelToLatLng', [ point ], marker, 'getPoint', function(zoom, pointA, pointB) { ... });

Asynchronous Methods

Asynchronous Methods Callback Value Description
GAsync(...) ... Performs one or more asynchronous requests in parallel. Arguments are of the form: (object1, methodName1 [, optional argument array], methodName2 [, optional argument array], ..., object2, methodName3 [, optional argument array], ..., callback) The callback is passed the return values of each asynchronous request, in the order that the method names appear in the arguments to this function.

class GDirections

This class is used to obtain driving directions results and display them on a map and/or a text panel.

Constructor

Constructor Description
GDirections(panel?) Creates a new instance of a directions object to request and store direction results. This directions object can then create directions given a query using the GDirections.load() method. The constructor takes an optional panel DIV element to display textual direction results. Additionally, the object contains three event listeners which you can intercept: "load": This event is triggered when the results of a directions query issued via GDirections.load() are available. Note that the load() method initiates a new query, which in turn triggers a "load" event once the query has finished loading. The "load" event is triggered before any overlay elements are added to the map/panel. "addoverlay": This event is triggered after the polyline and/or textual directions components are added to the map and/or DIV elements. Note that the "addoverlay" event is not triggered if neither of these elements are attached to a GDirections object. "error": This event is triggered if a directions request results in an error. Callers can use GDirections.getStatusAsync() to get more information about the error. When an "error" event occurs, no "load" or "addoverlay" events will be triggered.

Asynchronous Methods

Asynchronous Methods Callback Value Description
load(query, queryOpts?) none This method issues a new directions query. The query parameter is a string containing any valid directions query, e.g. "from: Seattle to: San Francisco" or "from: Toronto to: Ottawa to: New York". By default, if a map was specified during construction of the GDirections object, the query will request a polyline result. Otherwise, the result will contain only summary information about routes found. In order to override this behavior, i.e. to request polyline information even when no map was attached to this object, callers can use the queryOpts optional parameter. See the documentation for GDirectionsOptions for details. When directions results are received, this object clears old results, replacing them with new ones and updating the map with new results. Directions results consist of multiple routes (objects of type GRoute), one per consecutive pair of waypoints/addresses specified in the query. In turn, routes consist of multiple steps (objects of type GStep). If a previous load() request has not completed when a new call to load() is invoked, the previous request is cancelled. Thus, you can use a single GDirections object to issue directions requests serially, but to generate multiple requests in parallel, you must use multiple GDirections objects.
loadFromWaypoints(waypoints, queryOpts?) none Issues a new directions query using an array of waypoints as input instead of a single query string. Each entry in the array is a string representing an input address or a lat,lng point. See GDirections.load() for more details on the behavior of this method.
clear() none Clears any existing directions results, removes overlays from the map and panel, and cancels any pending load() requests.
getStatusAsync() Object Returns the status of the directions request. The returned object has the following form: {   code: 200   request: "directions" } The status code can take any of the values defined in GGeoStatusCode.
getBoundsAsync() GLatLngBounds This method is used to get the bounding box for the result of this directions query. Returns a GLatLngBounds object or null if no successful result is available.
getNumRoutesAsync() Number Returns the number of routes available in the result. For a successful query, this should be the total number of input waypoints minus 1. When no results are available (either because no query was issued or because the previous query was unsuccessful), this method returns 0.
getRouteAsync(i) GRoute Return the GRoute object for the ith route in the response.
getNumGeocodesAsync() Number Returns the number of geocoded entries available in the result. For a successful query, this should be equal to the total number of input waypoints. When no results are available (either because no query was issued or because the previous query was unsuccessful), this method returns 0.
getGeocodeAsync(i) Object Return the geocoded result for the ith waypoint. The structure of this object is identical to that of a single placemark in a response from the GClientGeocoder object.
getCopyrightsHtmlAsync() String Returns an HTML string containing the copyright information for this result.
getSummaryHtmlAsync() String Returns an HTML snippet containing a summary of the distance and time for this entire directions request. Note that this summary is the only information returned to a GDirections object constructed without an associated map or DIV element.
getDistanceAsync() Object Returns an object literal representing the total distance of the directions request (across all routes). The object contains two fields: a number called "meters" indicating the numeric value of the distance (in meters), and a string called "html" containing a localized string representation of the distance in the units that are predominant in the starting country of this set of directions.
getDurationAsync() Object Returns an object literal representing the total time of the directions request (across all routes). The object contains two fields: a number called "seconds" indicating the numeric value of the time (in seconds), and a string called "html" containing a localized string representation of the time.
getPolylineAsync() GPolyline Returns the GPolyline object associated with the entire directions response. Note that there is a single polyline that represents all the routes in the response. This object will be defined only after the directions results have been loaded (i.e. the "load" event has been triggered).
getMarkerAsync(i) GMarker Return the marker associated with the ith geocode. This method will return a non-null value only after the directions results have been loaded (i.e. the "load" event has been triggered).

class GDirectionsOptions

This class represents optional arguments to the GDirections.load() and GDirections.loadFromWaypoints() methods. It has no constructor, but is instantiated as an object literal.

Properties

Properties Type Description
locale String The locale to use for the directions result. For example, "en_US", "fr", "fr_CA", etc.
travelMode GTravelModes The mode of travel, such as driving (default) or walking.
getPolyline Boolean By default, the GDirections.load*() methods fetch polyline data only if a map is attached to the GDirections object. This field can be used to override this behavior and retrieve polyline data even when a map is not attached to the Directions object.
getSteps Boolean By default, the GDirections.load*() methods fetch steps data only if a panel is attached to the GDirections object. This field can be used to override this behavior and retrieve steps data even when a panel is not attached to the Directions object.
preserveViewport Boolean By default, when a Directions object has a map, the map is centered and zoomed to the bounding box of the the directions result. When this option is set to true, the viewport is left alone for this request (unless it was never set in the first place).

enum GTravelModes

Constants

Constants Description
G_TRAVEL_MODE_WALKING Walking
G_TRAVEL_MODE_DRIVING Driving

class GRoute

Objects of this class are created by the GDirections object to store information about a single route in a directions result. Clients should not directly create objects of this class.

Methods

Methods Return Value Description
getNumSteps() Number Returns the number of steps in this route.
getStep(i) GStep Return the GStep object for the ith step in this route.
getStartGeocode() Object Return the geocode result for the starting point of this route. The structure of this object is identical to that of a single placemark in a response from the GClientGeocoder object.
getEndGeocode() Object Return the geocode result for the ending point of this route. The structure of this object is identical to that of a single placemark in a response from the GClientGeocoder object.
getEndLatLng() GLatLng Returns a GLatLng object for the last point along the polyline for this route. Note that this point may be different from the lat,lng in GRoute.getEndGeocode() because getEndLatLng() always returns a point that is snapped to the road network. There is no corresponding getStartLatLng() method because that is identical to calling GRoute.getStep(0).getLatLng().
getSummaryHtml() String Returns an HTML snippet containing a summary of the distance and time for this route.
getDistance() Object Returns an object literal representing the total distance of this route. See GDirections.getDistance() for the structure of this object.
getDuration() Object Returns an object literal representing the total time of this route. See GDirections.getDuration() for the structure of this object.

class GStep

Objects of this class are created by the GDirections object to store information about a single step within a route in a directions result. This class does not have a public constructor. Clients should not directly create objects of this class.

Methods

Methods Return Value Description
getLatLng() GLatLng Returns a GLatLng object for the first point along the polyline for this step.
getPolylineIndex() Number Returns the index of the first point along the polyline for this step.
getDescriptionHtml() String Return an HTML string containing the description of this step.
getDistance() Object Returns an object literal representing the total distance of this step. See GDirections.getDistance() for the structure of this object.
getDuration() Object Returns an object literal representing the total time of this step. See GDirections.getDuration() for the structure of this object.