My favorites | English | Sign in

Faster JavaScript with Closure Tools New!

Google Maps JavaScript API V3 (Labs)

Google Maps API V3 Reference

Map class

This class extends MVCObject.

Constructor

Constructor Description
Map(mapDiv:Node, opts?:MapOptions) Creates a new map inside of the given HTML container, which is typically a DIV element.

Methods

Methods Return Value Description
fitBounds(bounds:LatLngBounds) None Sets the maps to fit to the given bounds.
getBounds() LatLngBounds Returns the lat/lng bounds of the current viewport. If the map is not yet initialized (i.e. the mapType is still null), or center and zoom have not been set then the result is null.
getCenter() LatLng
getDiv() Node
getMapTypeId() string
getZoom() number
panBy(x:number, y:number) None Changes the center of the map by the given distance in pixels. If the distance is less than both the width and height of the map, the transition is smoothly animated. Note that the map coordinate system increases from west to east (for x values) and north to south (for y values).
panTo(latLng:LatLng) None Changes the center of the map to the given LatLng. If the change is less than both the width and height of the map, the transition is smoothly animated.
setCenter(latlng:LatLng) None
setMapTypeId(mapTypeId:string) None
setOptions(options:MapOptions) None
setZoom(zoom:number) None

Events

Events Arguments Description
bounds_changed None This event is fired when the viewport bounds have changed.
center_changed None This event is fired when the map center property changes.
click MouseEvent This event is fired when the user clicks on the map (but not when they click on a marker or infowindow).
dblclick MouseEvent This event is fired when the user double-clicks on the map. Note that the click event will also fire, right before this one.
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.
dragstart None This event is fired when the user starts dragging the map.
idle None This event is fired when the map becomes idle after panning or zooming.
maptypeid_changed None This event is fired when the mapTypeId property changes.
resize None Developers should trigger this event on the map when the div changes size: google.maps.event.trigger(map, 'resize') .
rightclick MouseEvent This event is fired when the DOM contextmenu event is fired on the map container.
tilesloaded None This event is fired when the visible tiles have finished loading.
zoom_changed None This event is fired when the map zoom property changes.

MapOptions object specification

Properties

Properties Type Description
backgroundColor string Color used for the background of the Map div. This color will be visible when tiles have not yet loaded as a user pans.
center LatLng The initial Map center. Required.
disableDefaultUI boolean Enables/disables all default UI. May be overridden individually.
disableDoubleClickZoom boolean Enables/disables zoom and center on double click. Enabled by default.
draggable boolean If false, prevents the map from being dragged. Dragging is enabled by default.
draggableCursor string The name or url of the cursor to display on a draggable object.
draggingCursor string The name or url of the cursor to display when an object is dragging.
keyboardShortcuts boolean If false, prevents the map from being controlled by the keyboard. Keyboard shortcuts are enabled by default.
mapTypeControl boolean The initial enabled/disabled state of the Map type control.
mapTypeControlOptions MapTypeControlOptions The initial display options for the Map type control.
mapTypeId string The initial Map mapTypeId. Required.
navigationControl boolean The initial enabled/disabled state of the navigation control.
navigationControlOptions NavigationControlOptions The initial display options for the navigation control.
noClear boolean If true, do not clear the contents of the Map div.
scaleControl boolean The initial enabled/disabled state of the scale control.
scaleControlOptions ScaleControlOptions The initial display options for the scale control.
scrollwheel boolean If false, disables scrollwheel zooming on the map. The scrollwheel is enabled by default.
zoom number The initial Map zoom level. Required.

MapTypeId class

Identifiers for common MapTypes.

Constant

Constant Description
HYBRID This map type displays a transparent layer of major streets on satellite images.
ROADMAP This map type displays a normal street map.
SATELLITE This map type displays satellite images.
TERRAIN This map type displays maps with physical features such as terrain and vegetation.

MapTypeControlOptions object specification

Properties

Properties Type Description
style MapTypeControlStyle Style id. Used to select what style of map type control to display.

MapTypeControlStyle class

Identifiers for common MapTypesControls.

Constant

Constant Description
DEFAULT Uses the default map type control. The control which DEFAULT maps to will vary according to window size and other factors. It may change in future versions of the API.
DROPDOWN_MENU A dropdown menu for the screen realestate conscious.
HORIZONTAL_BAR The standard horizontal radio buttons bar.

NavigationControlOptions object specification

Properties

Properties Type Description
style NavigationControlStyle Style id. Used to select what style of navigation control to display.

NavigationControlStyle class

Identifiers for common types of navigation controls.

Constant

Constant Description
ANDROID The small zoom control similar to the one used by the native Maps application on Android.
DEFAULT The default navigation control. The control which DEFAULT maps to will vary according to map size and other factors. It may change in future versions of the API.
SMALL The small, zoom only control.
ZOOM_PAN The larger control, with the zoom slider and pan directional pad.

ScaleControlOptions object specification

Properties

Properties Type Description
style ScaleControlStyle Style id. Used to select what style of scale control to display.

ScaleControlStyle class

Identifiers for scale control ids.

Constant

Constant Description
DEFAULT The standard scale control.

MapPanes object specification

This object contains the DOM elements in which overlays are rendered. They are listed below in the order in which they appear from bottom to top.

Properties

Properties Type Description
floatPane Node This pane contains the info window. It is above all map overlays.
floatShadow Node This pane contains the info window shadow. It is above the overlayImage, so that markers can be in the shadow of the info window.
mapPane Node This pane is the lowest pane and is above the tiles.
overlayImage Node This pane contains the marker foreground images.
overlayLayer Node This pane contains polylines, polygons, ground overlays and tile layer overlays.
overlayMouseTarget Node This pane contains transparent elements that receive DOM mouse events for the markers. It is above the floatShadow, so that markers in the shadow of the info window can be clickable.
overlayShadow Node This pane contains the marker shadows.

MapCanvasProjection object specification

Methods

Methods Return Value Description
fromDivPixelToLatLng(pixel:Point) LatLng Computes the geographical coordinates from pixel coordinates in the div that holds the draggable map.
fromLatLngToDivPixel(latLng:LatLng) Point Computes the pixel coordinates of the given geographical location in the DOM element that holds the draggable map.
getWorldWidth() number The width of the world in pixels in the current zoom level.

Marker class

This class extends MVCObject.

Constructor

Constructor Description
Marker(opts?:MarkerOptions) Creates a marker with the options specified. If a map is specified, the marker is added to the map upon construction. Note that the position must be set for the marker to display.

Methods

Methods Return Value Description
getClickable() boolean
getCursor() string
getDraggable() boolean
getFlat() boolean
getIcon() string|MarkerImage
getMap() Map
getPosition() LatLng
getShadow() string|MarkerImage
getShape() Object
getTarget() string|MarkerImage
getTitle() string
getVisible() boolean
getZIndex() number
setClickable(flag:boolean) None
setCursor(cursor:string) None
setDraggable(flag:boolean) None
setFlat(flag:boolean) None
setIcon(icon:string|MarkerImage) None
setMap(map:Map) None Renders the marker on the specified map. If map is set to null, the marker will be removed.
setOptions(options:MarkerOptions) None
setPosition(latlng:LatLng) None
setShadow(shadow:string|MarkerImage) None
setShape(shape:Object) None
setTarget(target:string|MarkerImage) None
setTitle(title:string) None
setVisible(visible:boolean) None
setZIndex(zIndex:number) None

Events

Events Arguments Description
click Event This event is fired when the marker icon was clicked.
clickable_changed None This event is fired when the marker's clickable property changes.
cursor_changed None This event is fired when the marker's cursor property changes.
dblclick Event This event is fired when the marker icon was double clicked.
drag None This event is repeatedly fired while the user drags the marker.
dragend None This event is fired when the user stops dragging the marker.
draggable_changed None This event is fired when the marker's draggable property changes.
dragstart None This event is fired when the user starts dragging the marker.
flat_changed None This event is fired when the marker's flat property changes.
icon_changed None This event is fired when the marker icon property changes.
mousedown Event This event is fired when the DOM mousedown event is fired on the marker icon.
mouseout Event This event is fired when the mouse leaves the area of the marker icon.
mouseover Event This event is fired when the mouse enters the area of the marker icon.
mouseup Event This event is fired for the DOM mouseup on the marker.
position_changed None This event is fired when the marker position property changes.
rightclick Event This event is fired when the marker is right clicked on.
shadow_changed None This event is fired when the marker's shadow property changes.
shape_changed None This event is fired when the marker's shape property changes.
title_changed None This event is fired when the marker title property changes.
visible_changed None This event is fired when the marker's visible property changes.
zindex_changed None This event is fired when the marker's zIndex property changes.

MarkerOptions object specification

Properties

Properties Type Description
clickable boolean If true, the marker can be clicked
cursor string Mouse cursor to show on hover
draggable boolean If true, the marker can be dragged.
flat boolean If true, the marker shadow will not be displayed.
icon Icon for the foreground
map Map Map on which to display Marker.
position LatLng Marker position. Required.
shadow Shadow image
shape Object Image map region for drag/click. Array of x/y values that define the perimeter of the icon.
title string Rollover text
visible boolean If true, the marker is visible
zIndex number All Markers are displayed on the map in order of their zIndex, with higher values displaying in front of Markers with lower values. By default, Markers are displayed according to their latitude, with Markers of lower latitudes appearing in front of Markers at higher latitudes.

MarkerImage class

Constructor

Constructor Description
MarkerImage(url:string, size?:Size, origin?:Point, anchor?:Point) Defines an image to be used as the icon or shadow for a Marker. 'origin' and 'size' are used to select a segment of a sprite image and 'anchor' overrides the position of the anchor point from its default bottom middle position. The anchor of an image is the pixel to which the system refers in tracking the image's position. By default, the anchor is set to the bottom middle of the image (coordinates width/2, height). So when a marker is placed at a given LatLng, the pixel defined as the anchor is positioned at the specified LatLng. The MarkerImage cannot be changed once constructed.

Polyline class

A polyline is a linear overlay of connected line segments on the map. This class extends MVCObject.

Constructor

Constructor Description
Polyline(opts?:PolylineOptions) Create a polyline using the passed Polyline options, which specify both the path of the polyline and the stroke style to use when drawing the polyline. You may pass either an array of LatLngs or an MVCArray of LatLngs when constructing a polyline, though simple arrays are converted to MVCArrays within the polyline upon instantiation.

Methods

Methods Return Value Description
getPath() MVCArray.<LatLng> Retrieves the first path.
setMap(map:Map) None Renders this Polyline or Polygon on the specified map. If map is set to null, the Poly will be removed.
setOptions(options:PolylineOptions) None
setPath(path:
    MVCArray.<LatLng>|
    Array.<LatLng>
)
None Sets the first path. See Polyline options for more details.

Events

Events Arguments Description
click MouseEvent This event is fired when the DOM click event is fired on the Polyline.
dblclick MouseEvent This event is fired when the DOM dblclick event is fired on the Polyline.
mousedown MouseEvent This event is fired when the DOM mousedown event is fired on the Polyline.
mousemove MouseEvent This event is fired when the DOM mousemove event is fired on the Polyline.
mouseup MouseEvent This event is fired when the DOM mouseup event is fired on the Polyline.
rightclick MouseEvent This event is fired when the Polyline is right-clicked on.

PolylineOptions object specification

Properties

Properties Type Description
path MVCArray.<LatLng>|
Array.<LatLng>
The ordered sequence of coordinates of the Polyline. This path may be specified using either a simple array of LatLngs, or an MVCArray of LatLngs. Note that if you pass a simple array, it will be converted to an MVCArray Inserting or removing LatLngs in the MVCArray will automatically update the polyline on the map.
strokeColor string The stroke color in HTML hex style, ie. "#FFAA00"
strokeOpacity number The stroke opacity between 0.0 and 1.0
strokeWeight number The stroke width in pixels.

Polygon class

A polygon (like a polyline) defines a series of connected coordinates in an ordered sequence; additionally, polygons form a closed loop and define a filled region. This class extends MVCObject.

Constructor

Constructor Description
Polygon(opts?:PolygonOptions) Create a polygon using the passed Polygon options, which specify the polygon's path, the stroke style for the polygon's edges, and the fill style for the polygon's interior regions. A polygon may contain one or more paths, where each path consists of an array of LatLngs. You may pass either an array of LatLngs or an MVCArray of LatLngs when constructing these paths. Arrays are converted to MVCArrays within the polygon upon instantiation.

Methods

Methods Return Value Description
getPath() MVCArray.<LatLng> Retrieves the first path.
getPaths() MVCArray.<MVCArray.<LatLng>> Retrieves the paths for this Polygon.
setMap(map:Map) None Renders this Polyline or Polygon on the specified map. If map is set to null, the Poly will be removed.
setOptions(options:PolygonOptions) None
setPath(path:
    MVCArray.<LatLng>|
    Array.<LatLng>
)
None Sets the first path. See Polyline options for more details.
setPaths(paths:
    MVCArray.<MVCArray.<LatLng>>|
    MVCArray.<LatLng>|
    Array.<Array.<LatLng>>|
    Array.<LatLng>
)
None Sets the path for this Polygon.

Events

Events Arguments Description
click MouseEvent This event is fired when the DOM click event is fired on the Polygon.
dblclick MouseEvent This event is fired when the DOM dblclick event is fired on the Polygon.
mousedown MouseEvent This event is fired when the DOM mousedown event is fired on the Polygon.
mousemove MouseEvent This event is fired when the DOM mousemove event is fired on the Polygon.
mouseup MouseEvent This event is fired when the DOM mouseup event is fired on the Polygon.
rightclick MouseEvent This event is fired when the Polygon is right-clicked on.

PolygonOptions object specification

Properties

Properties Type Description
fillColor string The fill color in HTML hex style, ie. "#00AAFF"
fillOpacity number The fill opacity between 0.0 and 1.0
paths MVCArray.<MVCArray.<LatLng>>|
MVCArray.<LatLng>|
Array.<Array.<LatLng>>|
Array.<LatLng>
The ordered sequence of coordinates that designates a closed loop. Unlike polylines, a polygon may consist of one or more paths. As a result, the paths property may specify one or more arrays of LatLng coordinates. Simple polygons may be defined using a single array of LatLngs. More complex polygons may specify an array of arrays. Any simple arrays are convered into MVCArrays. Inserting or removing LatLngs from the MVCArray will automatically update the polygon on the map.
strokeColor string The stroke color in HTML hex style, ie. "#FFAA00"
strokeOpacity number The stroke opacity between 0.0 and 1.0
strokeWeight number The stroke width in pixels.

InfoWindow class

An overlay that looks like a bubble and is often connected to a marker. This class extends MVCObject.

Constructor

Constructor Description
InfoWindow(opts?:InfoWindowOptions) Creates an info window with the given options. An InfoWindow can be placed on a map at a particular position or above a marker, depending on what is specified in the options. Unless auto-pan is disabled, an InfoWindow will pan the map to make itself visible when it is opened. After constructing an InfoWindow, you must call open to display it on the map. The user can click the close button on the InfoWindow to remove it from the map, or the developer can call close() for the same effect.

Methods

Methods Return Value Description
close() None Closes this InfoWindow by removing it from the DOM structure.
getContent() string|Node
getPosition() LatLng
getZIndex() number
open(map:Map, anchor?:MVCObject) None Opens this InfoWindow on the given map. Optionally, an InfoWindow can be associated with an anchor. In the core API, the only anchor is the Marker class. However, an anchor can be any MVCObject that exposes the position property and optionally pixelBounds for calculating the pixelOffset (see InfoWindowOptions).
setContent(content:string|Node) None
setOptions(options:InfoWindowOptions) None
setPosition(position:LatLng) None
setZIndex(zIndex:number) None

Events

Events Arguments Description
closeclick None This event is fired when the close button was clicked.
content_changed None This event is fired when the content property changes.
domready None This event is fired when the <div> containing the InfoWindow's content is attached to the DOM. You may wish to monitor this event if you are building out your info window content dynamically.
position_changed None This event is fired when the position property changes.
zindex_changed None This event is fired when the InfoWindow's zIndex changes.

InfoWindowOptions object specification

Properties

Properties Type Description
content string|Node Content to display in the InfoWindow. This can be an HTML element, a plain-text string, or a string containing HTML. The InfoWindow will be sized according to the content. To set an explicit size for the content, set content to be a HTML element with that size.
disableAutoPan boolean Disable auto-pan on open. By default, the info window will pan the map so that it is fully visible when it opens.
maxWidth number Maximum width of the infowindow, regardless of content's width. This value is only considered if it is set before a call to open. To change the maximum width when changing content, call close, setOptions, and then open.
pixelOffset Size 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. If an InfoWindow is opened with an anchor, the pixelOffset will be calculated from the top-center of the anchor's bounds.
position LatLng The LatLng at which to display this InfoWindow. If the InfoWindow is opened with an anchor, the anchor's position will be used instead.
zIndex number All InfoWindows are displayed on the map in order of their zIndex, with higher values displaying in front of InfoWindows with lower values. By default, InfoWinodws are displayed according to their latitude, with InfoWindows of lower latitudes appearing in front of InfoWindows at higher latitudes. InfoWindows are always displayed in front of markers.

Geocoder class

A service for converting between an address and a LatLng.

Constructor

Constructor Description
Geocoder() Creates a new instance of a Geocoder that sends geocode requests to Google servers.

Methods

Methods Return Value Description
geocode(request:GeocoderRequest, callback:function(Array.<GeocoderResponse>, GeocoderStatus))) None Geocode a request.

GeocoderRequest object specification

The specification for a geocoding request to be sent to the Geocoder.

Properties

Properties Type Description
address string Address. Optional.
bounds LatLngBounds LatLngBounds within which to search. Optional.
country string Country code top-level domain within which to search. Optional.
language string Preferred language for results. Optional.
latLng LatLng LatLng about which to search. Optional.

GeocoderResponse object specification

An array of these objects are returned from the geocoder. Some fields in the response may not be returned for all requests - those are marked with a "?".

{types[]: String,
 formatted_address: String,
 address_components[]: {
  short_name: String,
  long_name: String,
  types[]: String
 },
 geometry: {
  location: LatLng,
  location_type: GeocoderLocationType,
  viewport: LatLngBounds,
  bounds: LatLngBounds?
 }
}
 

GeocoderStatus class

The status returned by the Geocoder on the completion of a call to geocode().

Constant

Constant Description
ERROR There was a problem contacting the Google servers.
INVALID_REQUEST This GeocoderRequest was invalid.
OK The response contains a valid GeocoderResponse.
OVER_QUERY_LIMIT The webpage has gone over the requests limit in too short a period of time.
REQUEST_DENIED The webpage is not allowed to use the geocoder.
UNKNOWN_ERROR A geocoding request could not be processed due to a server error. The request may succeed if you try again.
ZERO_RESULTS No result was found for this GeocoderRequest.

GeocoderLocationType class

Describes the type of location returned from a geocode.

Constant

Constant Description
APPROXIMATE The returned result is approximate.
GEOMETRIC_CENTER The returned result is the geometric center of a result such a line (e.g. street) or polygon (region).
RANGE_INTERPOLATED The returned result reflects an approximation (usually on a road) interpolated between two precise points (such as intersections). Interpolated results are generally returned when rooftop geocodes are unavilable for a street address.
ROOFTOP The returned result reflects a precise geocode.

DirectionsRenderer class

Renders directions retrieved in the form of a DirectionsResult object retrieved from the DirectionsService. This class extends MVCObject.

Constructor

Constructor Description
DirectionsRenderer(opts?:DirectionsRendererOptions) Creates the renderer with the given options. Directions can be rendered on a map (as visual overlays) or additionally on a <div> panel (as textual instructions).

Methods

Methods Return Value Description
getDirections() DirectionsResult Returns the renderer's current set of directions.
getMap() Map Returns the map on which the DirectionsResult is rendered.
getPanel() Node Returns the panel <div> in which the DirectionsResult is rendered.
getTripIndex() number Returns the current trip index in use by this DirectionsRenderer object.
setDirections(directions:DirectionsResult) None Set the renderer to use the result from the DirectionsService. Setting a valid set of directions in this manner will display the directions on the renderer's designated map and panel.
setMap(map:Map) None This method specifies the map on which directions will be rendered. Pass null to remove the directions from the map.
setPanel(panel:Node) None This method renders the directions in a <div>. Pass null to remove the content from the panel.
setTripIndex(tripIndex:number) None Set the index of the trip in the DirectionsResult object to render. By default, the first trip in the array will be rendered.

DirectionsRendererOptions object specification

This object defines the properties that can be set on a DirectionsRenderer object.

Properties

Properties Type Description
directions DirectionsResult The directions to display on the map and/or in a <div> panel, retrieved as a DirectionsResult object from DirectionsService.
hideTripList boolean This property indicates whether the renderer should provide UI to select amongst alternative trips. By default, this flag is false and a user-selectable list of trips will be shown in the directions' associated panel. To hide that list, set hideTripList to true.
map Map Map on which to display the directions.
panel Node The <div> in which to display the directions steps.
preserveViewport boolean By default, the input map is centered and zoomed to the bounding box of this set of directions. If this option is set to true, the viewport is left unchanged, unless the map's center and zoom were never set.
tripIndex number The index of the trip within the DirectionsResult object. The default value is 0.

DirectionsService class

A service for computing directions between two or more places.

Constructor

Constructor Description
DirectionsService() Creates a new instance of a DirectionsService that sends directions queries to Google servers.

Methods

Methods Return Value Description
route(request:DirectionsRequest, callback:function(DirectionsResult, DirectionsStatus))) None Issue a directions search request.

DirectionsRequest object specification

The specification for a directions query to be sent to the DirectionsService.

Properties

Properties Type Description
destination LatLng|string Location of destination. This can be specified as either a string to be geocoded or a LatLng. Required.
origin LatLng|string Location of origin. This can be specified as either a string to be geocoded or a LatLng. Required.
provideTripAlternatives boolean Whether or not trip alternatives should be provided. Optional.
region string Region code used as a bias for geocoding requests. Optional.
travelMode DirectionsTravelMode Type of routing requested. Required.
unitSystem DirectionsUnitSystem Preferred unit system to use when displaying distance. Defaults to the unit system used in the country of origin.
waypoints Array.<DirectionsWaypoint> Array of intermediate waypoints. Directions will be calculated from the origin to the destination by way of each waypoint in this array. Optional.

DirectionsTravelMode class

The valid travel modes that can be specified in a DirectionsRequest as well as the travel modes returned in a DirectionsStep.

Constant

Constant Description
DRIVING Specifies a driving directions request.
WALKING Specifies a walking directions request.

DirectionsUnitSystem class

The valid unit systems that can be specified in a DirectionsRequest.

Constant

Constant Description
IMPERIAL Specifies that distances in the DirectionsResult should be expressed in imperial units.
METRIC Specifies that distances in the DirectionsResult should be expressed in metric units.

DirectionsWaypoint object specification

A DirectionsWaypoint represents a location between origin and destination through which the trip should be routed.

Properties

Properties Type Description
location LatLng|string Waypoint location. Can be an address string or LatLng. Optional.
stopover boolean If true, indicates that this waypoint is a stop between the origin and destination. This has the effect of splitting the route into two. This value is true by default. Optional.

DirectionsStatus class

The status returned by the DirectionsService on the completion of a call to route().

Constant

Constant Description
INVALID_REQUEST The DirectionsRequest provided was invalid.
MAX_WAYPOINTS_EXCEEDED Too many DirectionsWaypoints were provided in the DirectionsRequest. The total allowed waypoints is 23, plus the origin, and destination.
NOT_FOUND At least one of the origin, destination, or waypoints could not be geocoded.
OK The response contains a valid DirectionsResult.
OVER_QUERY_LIMIT The webpage has gone over the requests limit in too short a period of time.
REQUEST_DENIED The webpage is not allowed to use the directions service.
UNKNOWN_ERROR A directions request could not be processed due to a server error. The request may succeed if you try again.
ZERO_RESULTS No route could be found between the origin and destination.

DirectionsResult object specification

The directions response in JSON format retrieved from the directions server. You can render these using a DirectionsRenderer or parse this object and render it yourself. You must display the warnings and copyrights as noted in the Maps API terms of service.

Properties

Properties Type Description
trips Array.<DirectionsTrip> An array of DirectionsTrips, each of which contains information about the routes and steps of which it is composed. There will only be one trip unless the DirectionsRequest was made with provideTripAlternatives set to true.

DirectionsTrip object specification

A single trip containing a set of routes in JSON format in a DirectionsResult.

Properties

Properties Type Description
copyrights string Copyrights text to be displayed for this trip.
routes Array.<DirectionsRoute> An array of DirectionsRoutes, each of which contains information about the steps of which it is composed. There will be one route for each waypoint or destination specified. So a trip with no waypoints will contain one DirectionsRoute and a route with one waypoint will contain two.
warnings Array.<string> Warnings to be displayed when showing these directions.

DirectionsRoute object specification

A single route consisting of a set of steps in JSON format in a DirectionsResult. Some fields in the route may not be returned for all requests.

Properties

Properties Type Description
distance DirectionsDistance The total distance covered by this route. This property may be undefined as the distance may be unknown.
duration DirectionsDuration The total duration of this route. This property may be undefined as the duration may be unknown.
end_geocode GeocoderResponse The DirectionsService calculates directions between locations by using the nearest transportation option (usually a road) at the start and end points. end_geocode indicates the actual geocoded destination, which may be different than the last step if, for example, the road is not near the destination.
start_geocode GeocoderResponse The DirectionsService calculates directions between locations by using the nearest transportation option (usually a road) at the start and end points. start_geocode indicates the actual geocoded origin, which may be different than the first step if, for example, the road is not near the origin.
steps Array.<DirectionsStep> An array of DirectionsSteps, each of which contains information about the individual steps in this route.

DirectionsStep object specification

A single DirectionsStep in JSON format in a DirectionsResult. Some fields may be undefined.

Properties

Properties Type Description
distance DirectionsDistance The distance covered by this step. This property may be undefined as the distance may be unknown.
duration DirectionsDuration The typical time required to perform this step in seconds and in text form. This property may be undefined as the duration may be unknown.
end_point LatLng The ending point of this step.
instructions string Instructions for this step.
start_point LatLng The starting point of this step.

DirectionsDistance object specification

A representation of distance as a numeric value and a display string.

Properties

Properties Type Description
text string A string representation of the distance value, using the DirectionsUnitSystem specified in the request.
value number The distance in meters.

DirectionsDuration object specification

A representation of duration as a numeric value and a display string.

Properties

Properties Type Description
text string A string representation of the duration value.
value number The duration in seconds.

MapsEventListener object specification

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

event namespace

Static Methods

Static Methods Return Value Description
addDomListener(instance:Object, eventName:string, handler:Function) MapsEventListener Cross browser event handler registration. This listener is removed by calling eventRemoveListener(handle) for the handle that is returned by this function.
addListener(instance:Object, eventName:string, handler:Function) MapsEventListener Adds the given listener function to the the given event name for the given object instance. Returns an identifier for this listener that can be used with eventRemoveListener().
clearInstanceListeners(instance:Object) None Removes all listeners for all events for the given instance.
clearListeners(instance:Object, eventName:string) None Removes all listeners for the given event for the given instance.
removeListener(listener:MapsEventListener) None Removes the given listener, which should have been returned by eventAddListener above.
trigger(instance:Object, eventName:string, var_args:*) None Triggers the given event. All arguments after eventName are passed as arguments to the listeners.

MouseEvent object specification

This object is returned from various mouse events on the map and overlays, and contains all the fields shown below.

Properties

Properties Type Description
latLng LatLng The latitude/longitude that was below the cursor when the event occurred.

LatLng class

LatLng is a point in geographical coordinates, latitude and longitude.

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

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

Constructor

Constructor Description
LatLng(lat:number, lng:number, noWrap?:boolean) Notice the ordering of latitude and longitude. If the noWrap flag is true, then the numbers will be used as passed, otherwise 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
equals(other:LatLng) boolean Comparison function.
lat() number Returns the latitude in degrees.
lng() number Returns the longitude in degrees.
toString() string Converts to string representation.
toUrlValue(precision?:number) string Returns a string of the form "lat,lng" for this LatLng. We round the lat/lng values to 6 decimal places by default.

LatLngBounds class

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

Constructor

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

Methods

Methods Return Value Description
contains(point:LatLng) boolean Returns true if the given lat/lng is in this bounds.
equals(other:LatLngBounds) boolean Returns true if this bounds approximately equals the given bounds.
extend(point:LatLng) None Extends this bounds to contain the given point.
getCenter() LatLng Computes the center of this LatLngBounds
getNorthEast() LatLng Returns the north-east corner of this bounds.
getSouthWest() LatLng Returns the south-west corner of this bounds.
intersects(other:LatLngBounds) boolean Returns true if this bounds shares any points with this bounds.
isEmpty() boolean Returns if the bounds are empty.
toSpan() LatLng Converts the given map bounds to a lat/lng span.
toString() string Converts to string.
toUrlValue(precision?:number) string Returns a string of the form "lat_lo,lng_lo,lat_hi,lng_hi" for this bounds, where "lo" corresponds to the southwest corner of the bounding box, while "hi" corresponds to the northeast corner of that box.
union(other:LatLngBounds) None Extends this bounds to contain the union of this and the given bounds.

MVCArray class

This class extends MVCObject.

Constructor

Constructor Description
MVCArray(array?:Array) A mutable MVC Array.

Methods

Methods Return Value Description
forEach(callback:function(*, number))) None Iterate over each element, calling the provided callback. The callback is called for each element like: callback(element, index).
getAt(i:number) * Get an element at the specified index.
getLength()
insertAt(i:number, elem:*) None Insert an element at the specified index.
removeAt(i:number) * Remove an element from the specified index.
setAt(i:number, elem:*) None Set an element at the specified index.

Point class

Constructor

Constructor Description
Point(x:number, y:number) A point on a two-dimensional plane.

Methods

Methods Return Value Description
equals(other:Point) boolean Compares two Points
toString() string Returns a string representation of this Point.

Size class

Constructor

Constructor Description
Size(width:number, height:number, widthUnit?:string, heightUnit?:string) Two-dimensonal size, where width is the distance on the x-axis, and height is the distance on the y-axis.

Methods

Methods Return Value Description
equals(other:Size) boolean Compares two Sizes.
toString() string Returns a string representation of this Size.

MVCObject class

Constructor

Constructor Description
MVCObject() Base class implementing KVO.

Methods

Methods Return Value Description
bindTo(key:string, target:MVCObject, targetKey:string, noNotify?:boolean) None Binds a View to a Model.
changed(key:string) None Generic handler for state changes. Override this in derived classes to handle arbitrary state changes.
get(key:string) * Gets a value.
set(key:string, value:*) None Sets a value.
setValues(values:Object) None Sets a collection of key-value pairs.
unbind(key:string) None Removes a binding. Unbinding will set the unbound property to the current value. The object will not be notified, as the value has not changed.

OverlayView class

You can implement this class if you want to display custom types of overlay objects on the map. This class extends MVCObject.

Constructor

Constructor Description
OverlayView() You should inherit from this class by setting your overlay's prototype to new OverlayView.prototype. You must implement three methods: onAdd(), draw(), and onRemove(). In the add() method, you should create DOM objects and append them as children of the panes. In the draw() method, you should position these elements. In the onRemove() method, you should remove the objects from the DOM. You must call setMap() with a valid Map object to trigger the call to the onAdd() method and setMap(null) in order to trigger the onRemove() method. The setMap() method can be called at the time of construction or at any point afterward when the overlay should be re-shown after removing. The draw() method will then be called whenever a map property changes that could change the position of the element, such as zoom, center, or map type.

Methods

Methods Return Value Description
draw() None Implement this method to draw or update the overlay. This method is called after onAdd() and when the position from projection.fromLatLngToPixel() would return a new value for a given LatLng. This can happen on change of zoom, center, or map type. It is not necessarily called on drag or resize.
getMap() Map
getPanes() MapPanes Returns the panes in which this OverlayView can be rendered. Only available after draw has been called.
getProjection() MapCanvasProjection Returns the MapCanvasProjection object associated with this OverlayView. Only available after draw has been called.
onAdd() None Implement this method to initialize the overlay DOM elements. This method is called once after setMap() is called with a valid map. At this point, panes and projection will have been initialized.
onRemove() None Implement this method to remove your elements from the DOM. This method is called once following a call to setMap(null).
setMap(map:Map) None Adds the overlay to the map.

Back to top