English | Site Directory

Google Maps API

Google Maps API Premier

Same great maps plus a SLA, support, and control over ads

Google Maps API Reference

The Google Maps API is now integrated with the Google AJAX API loader, which creates a common namespace for loading and using multiple Google AJAX APIs. This framework allows you to use the optional google.maps.* namespace for all classes, methods and properties you currently use in the Google Maps API, replacing the normal G prefix with this namespace. Don't worry: the existing G namespace will continue to be supported.


For example, the GMap2 object within the Google Maps API can also be defined as google.maps.Map2.


Note that this reference documentation refers only to the existing G namespace.

If you only want to use the map to display your content, then you need to know these classes, types, and functions:

If you want to extend the functionality of the maps API by implementing your own controls, overlays, or map types, then you also need to know these classes and types:

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(container, opts?) Creates a new map inside of the given HTML container, which is typically a DIV element. If no set of map types is given in the optional argument opts.mapTypes, the default set G_DEFAULT_MAP_TYPES is used. If no size is given in the optional argument opts.size, then the size of the container is used. If opts.size is given, then the container element of the map is resized accordingly. See class GMapOptions. Note: a Map needs to be centered before it can be used. You should immediately call GMap2.setCenter() to initialize a map created with this constructor.

Methods

Configuration

Methods Return Value Description
GMap2.enableDragging() none Enables the dragging of the map (enabled by default).
GMap2.disableDragging() none Disables the dragging of the map.
GMap2.draggingEnabled() Boolean Returns true iff the dragging of the map is enabled.
GMap2.enableInfoWindow() none Enables info window operations on the map (enabled by default).
GMap2.disableInfoWindow() none Closes the info window, if it is open, and disables the opening of a new info window.
GMap2.infoWindowEnabled() Boolean Returns true iff the info window is enabled.
GMap2.enableDoubleClickZoom() none Enables double click to zoom in and out (disabled by default). (Since 2.58)
GMap2.disableDoubleClickZoom() none Disables double click to zoom in and out. (Since 2.58)
GMap2.doubleClickZoomEnabled() Boolean Returns true iff double click to zoom is enabled. (Since 2.58)
GMap2.enableContinuousZoom() none Enables continuous smooth zooming for select browsers (disabled by default). (Since 2.58)
GMap2.disableContinuousZoom() none Disables continuous smooth zooming. (Since 2.58)
GMap2.continuousZoomEnabled() Boolean Returns true if continuous smooth zooming is enabled. (Since 2.58)
GMap2.enableGoogleBar() none Enables the GoogleBar, an integrated search control, to the map. When enabled, this control takes the place of the default Powered By Google logo. Note that this control is not enabled by default. (Since 2.92)
GMap2.disableGoogleBar() none Disables the GoogleBar integrated search control. When disabled, the default Powered by Google logo occupies the position formerly containing this control. Note that this control is already disabled by default. (Since 2.92)
GMap2.enableScrollWheelZoom() none Enables zooming using a mouse's scroll wheel. Note: scroll wheel zoom is disabled by default. (Since 2.78)
GMap2.disableScrollWheelZoom() none Disables zooming using a mouse's scroll wheel. Note: scroll wheel zoom is disabled by default. (Since 2.78)
GMap2.scrollWheelZoomEnabled() Boolean Returns a Boolean indicating whether scroll wheel zooming is enabled. (Since 2.78)

Controls

Methods Return Value Description
GMap2.addControl(control, position?) none Adds the control to the map. The position on the map is determined by the optional position argument. If this argument is absent, the default position of the control is used, as determined by the GControl.getDefaultPosition() method. A control instance must not be added more than once to the map.
GMap2.removeControl(control) none Removes the control from the map. It does nothing if the control was never added to the map.
GMap2.getContainer() Node Returns the DOM object that contains the map. Used by GControl.initialize().

Map Types

Methods Return Value Description
GMap2.getMapTypes() Array of GMapType Returns the array of map types registered with this map.
GMap2.getCurrentMapType() GMapType Returns the currently selected map type.
GMap2.setMapType(type) none Selects the given new map type. The type must be known to the map. See the constructor, and the method addMapType().
GMap2.addMapType(type) none Adds a new map type to the map. See section GMapType for how to define custom map types.
GMap2.removeMapType(type) none Removes the map type from the map. Will update the set of buttons displayed by the GMapTypeControl or GHierarchicalMapTypeControl and fire the removemaptype event.

Map State

Methods Return Value Description
GMap2.isLoaded() Boolean Returns true iff the map was initialized by setCenter() since it was created.
GMap2.getCenter() GLatLng Returns the geographical coordinates of the center point of the map view.
GMap2.getBounds() GLatLngBounds Returns the the visible rectangular region of the map view in geographical coordinates.
GMap2.getBoundsZoomLevel(bounds) 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.
GMap2.getSize() GSize Returns the size of the map view in pixels.
GMap2.getZoom() Number Returns the current zoom level.
GMap2.getDragObject() GDraggableObject Returns the draggable object used by this map. (Since 2.93)
GMap2.getEarthInstance(callback) none Retrieves the instance of the Google Earth Browser Plugin attached to this map, and calls the passed callback function once the instance is ready to receive commands, passing the earth instance (a GEPlugin object) as a parameter. This callback function may fire immediately if the Earth instance had previously been instantiated by setting the Google Earth map type via GMap2.setMapType(G_SATELLITE_3D_MAP). If the instance if not yet created, calling getEarthInstance will initialize the Google Earth Plug-in. (This asynchronous behavior is why this method requires a callback.) Note: if the initialization encounters an error, the callback function will pass a null parameter. Note that that while this method will create an Earth instance, it will not set the Earth map type as the current view. To so so, call GMap2.setMapType(G_SATELLITE_3D_MAP) explicitly, or allow the user to select this map type via the MapTypeControl. See the Google Earth API Developer's Guide for details on how to use the GEPlugin object. (Since 2.113)

Modify the Map State

Methods Return Value Description
GMap2.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 operations on a newly constructed GMap2 object until after this function is invoked.
GMap2.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.
GMap2.panBy(distance) none Starts a pan animation by the given distance in pixels.
GMap2.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.
GMap2.setZoom(level) none Sets the zoom level to the given new value.
GMap2.zoomIn() none Increments zoom level by one.
GMap2.zoomOut() none Decrements zoom level by one.
GMap2.savePosition() none Stores the current map position and zoom level for later recall by returnToSavedPosition().
GMap2.returnToSavedPosition() none Restores the map view that was saved by savePosition().
GMap2.checkResize() none Notifies the map of a change of the size of its container. Call this method after the size of the container DOM object has changed, so that the map can adjust itself to fit the new size.

Overlays

Methods Return Value Description
GMap2.addOverlay(overlay) none Adds an overlay to the map and fires the addoverlay event.
GMap2.removeOverlay(overlay) none Removes the overlay from the map. It is an error to try to remove an overlay that is not on the map. If the call is successful, it fires the removeoverlay event.
GMap2.clearOverlays() none Removes all overlays from the map, and fires the clearoverlays event.
GMap2.getPane(pane) Node Returns a DIV that holds the object in the layer identified by pane. Used by GOverlay instances in method GOverlay.initialize() instances to draw themselves on the map

Info Window

Methods Return Value Description
GMap2.openInfoWindow(latlng, 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.
GMap2.openInfoWindowHtml(latlng, 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.
GMap2.openInfoWindowTabs(latlng, 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.
GMap2.openInfoWindowTabsHtml(latlng, 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.
GMap2.showMapBlowup(latlng, opts?) none Opens an info window at the given point that contains a closeup view on the map around this point.
GMap2.updateInfoWindow(tabs, onupdate?) none Updates the content of the currently open GInfoWindow object, without repositioning. The info window is resized to fit the new content. The optional onupdate callback function is called after the info window content is actually changed. (Since 2.85)
GMap2.updateCurrentTab(modifier, onupdate?) none Updates the currently selected tab, causing a resize of the GInfoWindow object, without repositioning. The modifier function is used to modify the currently selected tab and is passed a GInfoWindowTab as an argument. The optional onupdate callback function is called after the info window displays the new content. (Since 2.85)
GMap2.closeInfoWindow() none Closes the currently open info window.
GMap2.getInfoWindow() 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

Methods Return Value Description
GMap2.fromContainerPixelToLatLng(pixel) GLatLng Computes the geographical coordinates of the point at the given pixel coordinates in the DOM element that contains the map on the page. This is helpful for when you implement interaction of custom controls with the map.
GMap2.fromLatLngToContainerPixel(latlng) GPoint Computes the pixel coordinates of the given geographical point in the DOM element that contains the map on the page. (Since 2.100)
GMap2.fromLatLngToDivPixel(latlng) 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.
GMap2.fromDivPixelToLatLng(pixel) GLatLng Computes the geographical coordinates from pixel coordinates in the div that holds the draggable map. This may be helpful for when you implement interaction with custom overlays that don't extend the GOverlay interface. If this doesn't give you the expected output, try the fromContainerPixelToLatLng method instead.

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, latlng, overlaylatlng This event is fired when the user clicks on the map with the mouse. A click event passes different arguments based on the context of the click, and whether or not the click occured on a clickable overlay. If the click does not occur on a clickable overlay, the overlay argument is null and the latlng argument contains the geographical coordinates of the point that was clicked. If the user clicks on an overlay that is clickable (such as a GMarker, GPolygon, GPolyline, or GInfoWindow), the overlay argument contains the overlay object, while the overlaylatlng argument contains the coordinates of the clicked overlay. In addition, a click event is then also fired on the overlay itself.
dblclick overlay, latlng 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 or other clickable overlay. The geographical coordinates of the point that was double clicked are passed in the latlng argument. The overlay argument is always set to null. (Since 2.83)
singlerightclick point, src, overlay? This event is fired when the DOM contextmenu event is fired on the map container. If the right click was on a marker or other clickable overlay, then the overlay is passed to the event handler in the overlay argument. The pixel coordinates (in the DOM element that holds the map) of the point that was right clicked and the source element of the DOM event are passed in the point and src arguments respectively. Note that if it is a double right click and double click to zoom is enabled, then the map zooms out and no singlerightclick event is fired. If, however, double click to zoom is disabled, two singlerightclick events will be fired. (Since 2.84)
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.
move none This event is fired, possibly repeatedly, while the map view is changing.
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.
infowindowbeforeclose none This event is fired before the info window closes. (Since 2.83)
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().
mouseover latlng This event is fired when the user moves the mouse over the map from outside the map.
mouseout latlng This event is fired when the user moves the mouse off the map.
mousemove latlng This event is fired when the user moves the mouse inside the map.
dragstart none This event is fired when the user starts dragging the map.
drag none This event is repeatedly fired while the user drags the map.
dragend none This event is fired when the user stops dragging the map.
load none This event is fired when the map setup is complete, and isLoaded() would return true. This means position, zoom, and map type are all initialized, but tile images may still be loading. (Since 2.52)

class GMapOptions

This class represents optional arguments to the GMap2 constructor. It has no constructor, but is instantiated as an object literal.

Properties

Properties Type Description
size GSize Sets the size in pixels of the map. The container that is passed to the map constructor will be resized to the given size. By default, the map will assume the size of its container.
mapTypes Array of GMapType Array of map types to be used by this map. By default, G_DEFAULT_MAP_TYPES is used. You can use this option to restrict the set of predefined map types that is displayed on the map, or to pass your own map types to the map. See also GMap2.addMapType().
draggableCursor String The cursor to display when the map is draggable. (Since 2.59)
draggingCursor String The cursor to display while dragging the map. (Since 2.59)
googleBarOptions GGoogleBarOptions This property specifies the options to configure the GGoogleBar search control. These options are passed to the GMapOptions object literal when the map is constructed, and are used to construct the local GGoogleBar control when GMap2.enableGoogleBar() is called. (Since 2.95)
backgroundColor String This property specifies the color to display behind the map tiles. The color can be any valid W3C standard color value. (Since 2.119)

class GGoogleBarOptions

This class represents options passed within the googleBarOptions parameter to the GMapOptions object. It has no constructor, but is instantiated as an object literal. Note that the GGoogleBar object, like the GInfoWindow is not constructed, but is automatically attached to the map object, and enabled through properties described here.

Properties

Properties Type Description
showOnLoad Boolean When set to true, this property displays the search box within the GoogleBar (provided the control is enabled and the map is loaded). By default, the search box within the control is hidden and is only expanded upon clicking the control's magnifying glass. (Since 2.95)
linkTarget GGoogleBarLinkTarget This property lets you specify the target for links embedded within the search results of the GoogleBar. The default value, G_GOOGLEBAR_LINK_TARGET_BLANK, specifies that links will open within a new window. (Since 2.95)
resultList GGoogleBarResultList or Element This property lets you specify the style of the search result list for the GoogleBar, which may be one of the following: G_GOOGLEBAR_RESULT_LIST_INLINE (default) places the result list in a table above the search box, G_GOOGLEBAR_RESULT_LIST_SUPPRESS replaces the list with a set of next/previous buttons, and passing a block-level DOM Element places the list within a container of your choice (typically a <div> element). (Since 2.95)
suppressInitialResultSelection Boolean This property suppresses displaying the first result within its own info window upon completion of a search in the GoogleBar (which is the default behavior). (Since 2.95)
suppressZoomToBounds Boolean This property suppresses automatic panning and zooming to the set of results upon completion of a search in the GoogleBar. (This property suppresses the default behavior.) (Since 2.95)
onIdleCallback Function This property specifies a callback function to be invoked when the GoogleBar finishes searching and the search results are dismissed. (Since 2.95)
onSearchCompleteCallback Function This property specifies a callback function to be invoked when the GoogleBar finishes searching and the search completes. It is passed the GlocalSearch object associated with the search control. This callback function is called before results are placed on the map or into the results list. (Since 2.95)
onGenerateMarkerHtmlCallback Function This property lets you specify a callback function to be invoked when the info window for a search result marker is opened. The function should be passed a GMarker, generated HTML string, and GlocalSearchResult (in that order) and must return the modified HTML string to be displayed in the info window. (Since 2.95)
onMarkersSetCallback Function This property lets you specify a callback function to be invoked when the GGoogleBar completes creation of its markers and places them on the map. This function must be passed an array of objects of the form {result: GlocalSearch, marker: GMarker}. (Since 2.95)

enum GGoogleBarListingTypes

These constants restrict the type of results returned by a local search with the GGoogleBar. This search behavior is set within the GGoogleBarOptions.listingTypes property.

Constants

Constants Description
G_GOOGLEBAR_TYPE_BLENDED_RESULTS This constant indicates that searches from the map's GGoogleBar should return all types of results (KML, businesses, geocodes, etc). (Since 2.113)
G_GOOGLEBAR_TYPE_KMLONLY_RESULTS This constant indicates that searches from the map's GGoogleBar should return only results from indexed KML/KMZ/GeoRSS files. (Since 2.113)
G_GOOGLEBAR_TYPE_LOCALONLY_RESULTS This constant indicates that searches from the map's GGoogleBar should return only business and geocode results. (Since 2.113)

enum GGoogleBarLinkTarget

These constants are passed in GGoogleBarOptions.linkTarget, and define the default target for links in result info windows.

Constants

Constants Description
G_GOOGLEBAR_LINK_TARGET_BLANK Corresponds to target = '_blank'.
G_GOOGLEBAR_LINK_TARGET_PARENT Corresponds to target = '_parent'.
G_GOOGLEBAR_LINK_TARGET_SELF Corresponds to target = '_self'.
G_GOOGLEBAR_LINK_TARGET_TOP Corresponds to target = '_top'.

enum GGoogleBarResultList

These constants are passed in GGoogleBarOptions.resultList, and define how the result list is displayed.

Constants

Constants Description
G_GOOGLEBAR_RESULT_LIST_INLINE This corresponds to the default style, where the result list is displayed in tabular form on the map.
G_GOOGLEBAR_RESULT_LIST_SUPPRESS This corresponds to the default style, where the result list is hidden and replaced with next/previous buttons..

enum GMapPane

These constants define the stacking order (z-order) used by the map and objects on the map for display purposes. Each pane defines a set of similar display objects to show on the map, and each pane defines a unique z-order on the map. Panes with a higher z-order are shown "on top" of panes with a lower z-order. (Note that objects within a given pane may exhibit their own z-order precedence as well; some object may appear on top of other objects within that pane.)

You need to use these constants if you subclass from GOverlay, so that you can place your custom overlay in one of the panes.

The following constants are listed in order from lowest z-order (bottom) to the highest (top).

Constants

Constants Description
G_MAP_MAP_PANE This pane is the lowest pane and is above the tiles.
G_MAP_OVERLAY_LAYER_PANE This pane contains polylines, polygons, ground overlays and tile layer overlays. (Since 2.127)
G_MAP_MARKER_SHADOW_PANE This pane contains the marker shadows.
G_MAP_MARKER_PANE This pane contains the marker foreground images.
G_MAP_FLOAT_SHADOW_PANE This pane contains the info window shadow. It is above the G_MAP_MARKER_PANE, so that markers can be in the shadow of the info window.
G_MAP_MARKER_MOUSE_TARGET_PANE This pane contains transparent elements that receive DOM mouse events for the markers. Is is above the G_MAP_FLOAT_SHADOW_PANE, so that markers in the shadow of the info window can be clickable.
G_MAP_FLOAT_PANE This pane contains the info window. It is above all map overlays.

class GKeyboardHandler

Instantiate this class to add keyboard bindings to a map. The key bindings are the same as for the maps application.

Key(s) Action
up, down, left, right Moves the map continuously while the key is pressed. Two keys can be pressed simultaneously in order to move diagonally.
page down, page up, home, end Pans the map by 3/4 its size in the corresponding direction, with a nice animation. This corresponds to the arrow buttons in the GLargeMapControl and the GSmallMapControl.
+, - Zooms one level in or out, respectively. This corresponds to the + and - buttons in the GLargeMapControl and the GSmallMapControl.

Constructor

Constructor Description
GKeyboardHandler(map) Installs keyboard event handler for the map passed as argument.

interface GOverlay

This interface is implemented by the GMarker, GPolyline, GTileLayerOverlay and GInfoWindow classes in the maps API library. You can implement it if you want to display custom types of overlay objects on the map. An instance of GOverlay can be put on the map with the method GMap2.addOverlay(). The map will then call the method GOverlay.initialize() on the overlay instance to display itself on the map initially. Whenever the map display changes, the map will call GOverlay.redraw() so that the overlay can reposition itself if necessary. The overlay instance can use the method GMap2.getPane() to get hold of one or more DOM container elements to attach itself to.

Constructor

Constructor Description
GOverlay() This constructor creates dummy implementations for the methods. Still, when inheriting from this class, your derived class constructor should call this constructor for completeness.

Static Methods

Static Methods Return Value Description
GOverlay.getZIndex(latitude) Number Returns a CSS z-index value for a given latitude. It computes a z index such that overlays further south are on top of overlays further north, thus creating the 3D appearance of marker overlays.

Abstract Methods

Abstract Methods Return Value Description
GOverlay.initialize(map) none Called by the map after the overlay is added to the map using GMap2.addOverlay(). The overlay object can draw itself into the different panes of the map that can be obtained using GMap2.getPane().
GOverlay.remove() none Called by the map after the overlay is removed from the map using GMap2.removeOverlay() or GMap2.clearOverlays(). The overlay must remove itself from the map panes here.
GOverlay.copy() GOverlay Returns an uninitialized copy of itself that can be added to the map.
GOverlay.redraw(force) none Called by the map when the map display has changed. The argument force will be true if the zoom level or the pixel offset of the map view has changed, so that the pixel coordinates need to be recomputed.

class GInfoWindow

GInfoWindow has no constructor. It is created by the map and accessed by its method GMap2.getInfoWindow().

Methods

Methods Return Value Description
GInfoWindow.selectTab(index) none Selects the tab with the given index. This has the same effect as clicking on the corresponding tab.
GInfoWindow.hide() none Makes the info window invisible. NOTE: This doesn't close the info window. It can be made visible again using show().
GInfoWindow.show() none Makes the info window visible if its currently invisible.
GInfoWindow.isHidden() Boolean Returns true iff the info window is hidden. This includes the state that it's closed.
GInfoWindow.reset(latlng, 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.
GInfoWindow.getPoint() 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.
GInfoWindow.getPixelOffset() 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.
GInfoWindow.getSelectedTab() Number Returns the index, starting at 0, of the current selected tab.
GInfoWindow.getTabs() Array of GInfoWindowTabs Returns the array of tabs in this info window. (Since 2.59)
GInfoWindow.getContentContainers() Array of Node Returns the array of DOM nodes that hold the content of the tabs of this info window. (Since 2.59)
GInfoWindow.enableMaximize() none Enables maximization of the info window. A maximizable info window expands to fill most of the map with contents specified via the maxContent and maxTitle properties of GInfoWindowOptions. The info window must have been opened with maxContent or maxTitle options in order for enableMaximize() or disableMaximize to have any effect. An info window opened with maxContent or maxTitle will have maximization enabled by default. (Since 2.93)
GInfoWindow.disableMaximize() none Disables maximization of the info window. The infowindow must have been opened with maxContent or maxTitle options. Note that if the info window is currently opened, this function will remove the maximize buton but will not restore the window to its minimized state. (Since 2.93)
GInfoWindow.maximize() none Maximizes the infowindow. The infowindow must have been opened with maxContent or maxTitle options, and it must not have had its maximization disabled through disableMaximize. (Since 2.93)
GInfoWindow.restore() none Restores the info window to its default (non-maximized) state. The infowindow must have been opened with maxContent or maxTitle options. (Since 2.93)

Events

Events Arguments Description
closeclick none This event is fired when the info window close button is clicked.
maximizeclick none Signals that the info window is about to be maximized. (Since 2.93)
maximizeend none Signals that the info window has completed maximization. (Since 2.93)
restoreclick none Signals that the info window is about to be restored to the non-maximized state. (Since 2.93)
restoreend none Signals that the info window has completed the restore operation to the non-maximized state. (Since 2.93)

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 GMarker.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(), the bindInfoWindow*() variants, 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
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.
noCloseOnClick Boolean Indicates whether or not the info window should close for a click on the map that was not on a marker. If set to true, the info window will not close when the map is clicked. The default value is false. (Since 2.83)
onOpenFn Function Function is called after the info window is opened and the content is displayed.
onCloseFn Function Function is called when the info window is closed.
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.
maxContent String Specifies content to be shown when the infowindow is maximized. The content may be either an HTML string or an HTML DOM element. (Since 2.93)
maxTitle String Specifies title to be shown when the infowindow is maximized. The content may be either an HTML string or an HTML DOM element. (Since 2.93)
pixelOffset GSize Specifies a number of pixels in the up (x) and right (y) direction to move the infowindow away from the given GLatLng. (Since 2.98)

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 latlng, 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(latlng, icon?, inert?) Creates a marker at the passed latlng 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. (Deprecated since 2.50)
GMarker(latlng, opts?) Creates a marker at the latlng with options specified in GMarkerOptions. By default markers are clickable & have the default icon G_DEFAULT_ICON. (Since 2.50)

Methods

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

Methods Return Value Description
GMarker.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.
GMarker.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.
GMarker.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.
GMarker.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.
GMarker.bindInfoWindow(content, opts?) none Binds the given DOM node to this marker. The content within this node will be automatically displayed in the info window when the marker is clicked. Pass content as null to unbind. (Since 2.85)
GMarker.bindInfoWindowHtml(content, opts?) none Binds the given HTML to this marker. The HTML content will be automatically displayed in the info window when the marker is clicked. Pass content as null to unbind. (Since 2.85)
GMarker.bindInfoWindowTabs(tabs, opts?) none Binds the given GInfoWindowTabs (provided as DOM nodes) to this marker. The content within these tabs' nodes will be automatically displayed in the info window when the marker is clicked. Pass tabs as null to unbind. (Since 2.85)
GMarker.bindInfoWindowTabsHtml(tabs, opts?) none Binds the given GInfoWindowTabs (provided as strings of HTML) to this marker. The HTML content within these tabs will be automatically displayed in the info window when the marker is clicked. Pass tabs as null to unbind. (Since 2.85)
GMarker.closeInfoWindow() none Closes the info window only if it belongs to this marker. (Since 2.85)
GMarker.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.
GMarker.getIcon() GIcon Returns the icon of this marker, as set by the constructor.
GMarker.getTitle() String Returns the title of this marker, as set by the constructor via the GMarkerOptions.title property. Returns undefined if no title is passed in. (Since 2.85)
GMarker.getPoint() GLatLng Returns the geographical coordinates at which this marker is anchored, as set by the constructor or by setPoint(). (Deprecated since 2.88)
GMarker.getLatLng() GLatLng Returns the geographical coordinates at which this marker is anchored, as set by the constructor or by setLatLng(). (Since 2.88)
GMarker.setPoint(latlng) none Sets the geographical coordinates of the point at which this marker is anchored. (Deprecated since 2.88)
GMarker.setLatLng(latlng) none Sets the geographical coordinates of the point at which this marker is anchored. (Since 2.88)
GMarker.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.
GMarker.disableDragging() none Disables the marker from being dragged and dropped around the map.
GMarker.draggable() Boolean Returns true if the marker has been initialized via the constructor using GMarkerOptions.draggable = true. Otherwise, returns false.
GMarker.draggingEnabled() Boolean Returns true if the marker is currently enabled for the user to drag on the map.
GMarker.setImage(url) none Requests the image specified by the url to be set as the foreground image for this marker. 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. (Since 2.75)
GMarker.hide() none Hides the marker if it is currently visible. Note that this function triggers the event GMarker.visibilitychanged in case the marker is currently visible. (Since 2.77)
GMarker.show() none Shows the marker if it is currently hidden. Note that this function triggers the event GMarker.visibilitychanged in case the marker is currently hidden. (Since 2.77)
GMarker.isHidden() Boolean Returns true if the marker is currently hidden. Otherwise returns false. (Since 2.77)

Events

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

Events Arguments Description
click latlng This event is fired when the marker icon was clicked, passing in the current coordinate of the marker within its latlng argument. Notice that this event will also fire for the map, with the marker passed as the first argument to the event handler there.
dblclick latlng This event is fired when the marker icon was double-clicked, passing in the current coordinate of the marker within its latlng argument. Notice that this event will not fire for the map, because the map centers on double-click as a hardwired behavior.
mousedown latlng This event is fired when the DOM mousedown event is fired on the marker icon, passing in the current coordinate of the marker within its latlng argument. Notice that the marker will stop the mousedown DOM event, so that it doesn't cause the map to start dragging.
mouseup latlng This event is fired for the DOM mouseup on the marker, and passing in the current coordinate of the marker within its latlng argument. Notice that the marker will not stop the mousedown DOM event, because it will not confuse the drag handler of the map.
mouseover latlng This event is fired when the mouse enters the area of the marker icon, passing in the current coordinate of the marker within its latlng argument.
mouseout latlng This event is fired when the mouse leaves the area of the marker icon, passing in the current coordinate of the marker within its latlng argument.
infowindowopen none This event is fired when the info window of the map was opened through this marker.
infowindowbeforeclose none This event is fired before the info window of the map that was opened through this marker is closed. (Since 2.83)
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 latlng If the marker is enabled for dragging, this event is fired when the marker dragging begins, passing in the current coordinate of the marker within its latlng argument.
drag latlng If the marker is enabled for dragging, this event is fired when the marker is being dragged, passing in the current coordinate of the marker within its latlng argument.
dragend latlng If the marker is enabled for dragging, this event is fired when the marker ceases to be dragged, passing in the current coordinate of the marker within its latlng argument.
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. (Since 2.77)

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. (Since 2.50)
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. (Since 2.63)
title String This string will appear as tooltip on the marker, i.e. it will work just as the title attribute on HTML elements. (Since 2.50)
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. (Since 2.50)
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, bouncy and auto-pan enabled by default. The default value for this option is false. (Since 2.61)
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. (Since 2.61)
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. (Since 2.61)
autoPan Boolean Auto-pan the map as you drag the marker near the edge. If the marker is draggable the default value for this option is true. (Since 2.87)
zIndexProcess Function This function is used for changing the z-Index order of the markers when they are overlaid on the map and is also called when their infowindow is opened. The default order is that the more southerly markers are placed higher than more northerly markers. This function is passed in the GMarker object and returns a number indicating the new z-index. (Since 2.98)

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(latlngs, 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.

Factory Methods

Factory Methods Return Value Description
GPolyline.fromEncoded(color?, weight?, opacity?, latlngs, zoomFactor, levels, numLevels) GPolyline Creates a polyline from encoded strings of aggregated coordinates and levels. color is a string that contains a hexadecimal numeric HTML style, i.e. #RRGGBB. weight is the width of the line in pixels. opacity is a number between 0 and 1. latlngs is a string containing the encoded latitude and longitude coordinates. levels is a string containing the encoded polyline zoom level groups. numLevels is the number of zoom levels contained in the encoded levels string. zoomFactor is the magnification between adjacent sets of zoom levels in the encoded levels string. Together, these two values determine the precision of the levels within an encoded polyline. The line will be antialiased and semitransparent. (Since 2.63)

Methods

Methods Return Value Description
GPolyline.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(). (Since 2.111)
GPolyline.disableEditing() none Reverses the effects of enableEditing, removing all control points from the line and rendering it uneditable by the user. (Since 2.111)
GPolyline.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. (Since 2.111)
GPolyline.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. (Since 2.111)
GPolyline.getVertexCount() Number Returns the number of vertices in the polyline. (Since 2.46)
GPolyline.getVertex(index) GLatLng Returns the vertex with the given index in the polyline. (Since 2.46)
GPolyline.getLength() Number Returns the length (in meters) of the polyline along the surface of a spherical Earth. (Since 2.85)
GPolyline.getBounds() GLatLngBounds Returns the bounds for this polyline. (Since 2.85)
GPolyline.hide() none Hides the polyline if it is both currently visible and GPolyline.supportsHide() returns true. Note that this function triggers the event GPolyline.visibilitychanged in case the polyline is currently visible. (Since 2.87)
GPolyline.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(). (Since 2.111)
GPolyline.isHidden() Boolean Returns true if the polyline is currently hidden. Otherwise returns false. (Since 2.87)
GPolyline.show() none Shows the polyline if it is currently hidden. Note that this function triggers the event GPolyline.visibilitychanged in case the polyline is currently hidden. (Since 2.87)
GPolyline.supportsHide() Boolean Returns true if GPolyline.hide() is supported in the current environment for GPolyline objects. Otherwise returns false. (Since 2.87)
GPolyline.setStrokeStyle(style) none Changes the style of the polyline. The GPolyline must already be added to the map via GMap2.addOverlay(). (Since 2.111)

Events

Events Arguments Description
remove none This event is fired when the polyline is removed from the map, using GMap2.removeOverlay() or GMap2.clearOverlays().
visibilitychanged isVisible This event is fired when the visibility state of the polyline toggles from visible to hidden or vice versa. The isVisible argument reflects the state of the polyline after completion of this visibility state. (Since 2.87)
click latlng This event is fired when the polyline is clicked, passing in the clicked coordinate of the line within its latlng argument. Note that this event also subsequently triggers a "click" event on the map, where the polyline is passed as the overlay argument within that event. (Since 2.88)
mouseover none This event is fired when the mouse moves onto the polyline. (Since 2.111)
mouseout none This event is fired when the mouse moves off of the polyline. (Since 2.111)
lineupdated none This event is fired when either the style or shape of the polyline is updated. (Since 2.111)
endline none This event is fired when line drawing (initiated by call to GPolyline.enableDrawing) is completed by the user. (Since 2.111)
cancelline none This event is fired when line drawing (initiated by call to GPolyline.enableDrawing) is aborted by the user. (Since 2.111)

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
clickable Boolean Toggles whether or not the polyline is clickable. The default value for this option is true, i.e. if the option is not specified, the polyline will be clickable. (Since 2.91)
geodesic Boolean Render each edge of the polyline as a geodesic (a segment of a "great circle"). A geodesic is the shortest path between two points along the surface of the Earth. (Since 2.84)

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 This property specifies the maximum number of vertices permitted for this polyline. Once this number is reached, no more may be added. (Since 2.111)
fromStart Boolean This property specifies whether enableDrawing should add points from the start rather than from the end, which is the default. (Since 2.111)

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 This property specifies a string that contains a hexadecimal numeric HTML style, i.e. #RRGGBB. (Since 2.111)
weight Number This property specifies the width of the line in pixels. (Since 2.111)
opacity Number This property specifies the opacity of the polyline as a fractional value between 0 (transparent) and 1 (opaque). (Since 2.111)

class GPolygon

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

Constructor

Constructor Description
GPolygon(latlngs, strokeColor?, strokeWeight?, strokeOpacity?, fillColor?, fillOpacity?, opts?) 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. (Since 2.69)

Factory Methods

Factory Methods Return Value Description
GPolygon.fromEncoded(polylines, fill?, color?, opacity?, outline?) GPolygon Creates a polygon (consisting of a number of polylines) from encoded strings of aggregated coordinates and levels. polylines contains an associative array of constituent polylines, encoded in the same format as described in the GPolyline.fromEncoded documentation. fill specifies whether to fill in the polygon with a certain color. opacity and outline specifies whether to stroke the polygon with the polyline's color, weight and opacity. In case multiple values are specified in polylines, the first polyline's values are taken. (Since 2.78)

Methods

Methods Return Value Description
GPolygon.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(). (Since 2.111)
GPolygon.disableEditing() none Reverses the effects of enableEditing, removing all control points from the line and rendering it uneditable by the user. (Since 2.111)
GPolygon.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. (Since 2.111)
GPolygon.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. (Since 2.111)
GPolygon.getVertexCount() Number Returns the number of vertices in the polygon. (Since 2.69)
GPolygon.getVertex(index) GLatLng Returns the vertex with the given index in the polygon. (Since 2.69)
GPolygon.getArea() Number Returns the area (in square meters) of the polygon, assuming a spherical Earth. (Since 2.85)
GPolygon.getBounds() GLatLngBounds Returns the bounds for this polygon. (Since 2.85)
GPolygon.hide() none Hides the polygon if it is both currently visible and GPolygon.supportsHide returns true. Note that this function triggers the event GPolygon.visibilitychanged in case the polygon is currently visible. (Since 2.87)
GPolygon.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(). (Since 2.111)
GPolygon.isHidden() Boolean Returns true if the polygon is currently hidden. Otherwise returns false. (Since 2.87)
GPolygon.show() none Shows the polygon if it is currently hidden. Note that this function triggers the event GPolygon.visibilitychanged in case the polygon is currently hidden. (Since 2.87)
GPolygon.supportsHide() Boolean Returns true if GPolygon.hide() is supported in the current environment for GPolygon objects. Otherwise returns false. (Since 2.87)
GPolygon.setFillStyle(style) none Changes the fill style of the polygon. The GPolygon must already be added to the map via GMap2.addOverlay(). (Since 2.111)
GPolygon.setStrokeStyle(style) none Changes the line style of the polygon. The GPolygon must already be added to the map via GMap2.addOverlay(). (Since 2.111)

Events

<
Events Arguments Description
remove none This event is fired when the polygon is removed from the map, using GMap2.removeOverlay() or GMap2.clearOverlays().
visibilitychanged isVisible This event is fired when the visibility state of the polygon toggles from visible to hidden or vice versa. The isVisible argument reflects the state of the polygon after completion of this visibility state. (Since 2.87)