Map APIMap()Constructor


Example

Create a Google map:

var map=new google.maps.Map(document.getElementById("googleMap"),mapOpt);

Try it Yourself »

Definition and Usage

The Map() constructor creates a new map and inserts it into the specified HTML element (a <div> element).


Syntax

new google.maps.Map(HTMLElement,MapOptions)

Parameter value

Parameter Description
HTMLElement Specifies the HTML element in which to place the map.
MapOptions A MapOptions object with map initialization variables/options.

Map() methods

Method Return value Description
fitBounds(LatLngBounds) None Sets the viewport to contain the given bounds.
getBounds() LatLng,LatLng Returns the southwest latitude/longitude and northeast latitude/longitude of the current viewport.
getCenter() LatLng Returns the latitude/longitude of the map's center.
getDiv() Node Returns the DOM object that contains the map.
getHeading() number Returns the compass heading of the aerial imagery (supported for SATELLITE and HYBRID map types).
getMapTypeId() HYBRID ROADMAP SATELLITE TERRAIN Returns the current map type.
getProjection() Projection Returns the current Projection.
getStreetView() StreetViewPanorama Returns the default StreetViewPanorama bound to the map.
getTilt() number Returns the angle of incidence in degrees of the aerial imagery (supported for SATELLITE and HYBRID map types).
getZoom() number Returns the current zoom level of the map.
panBy(xnumber,ynumber) None Changes the center of the map by the given distance in pixels.
panTo(LatLng) None Changes the center of the map to the given LatLng.
panToBounds(LatLngBounds) None Pans the map by the minimum distance required to contain the given LatLngBounds.
setCenter(LatLng) None
setHeading(number) None Sets the compass direction of the aerial imagery (measured in degrees), with north as the base direction.
setMapTypeId(MapTypeId) None Changes the map type to display.
setOptions(MapOptions) None
setStreetView(StreetViewPanorama) None Binds a StreetViewPanorama to the map.
setTilt(number) None Sets the angle of incidence in degrees of the aerial imagery (supported for SATELLITE and HYBRID map types).
setZoom(number) None

Map() properties

Attribute Type Description
controls Array.<MVCArray.<Node>> Extra controls to attach to the map.
mapTypes MapTypeRegistry A registry of MapType instances keyed by string ID.
overlayMapTypes MVCArray.<MapType> Extra map types to overlay.

Map() events

Event Parameter Description
bounds_changed None This event is triggered when the viewport bounds change.
center_changed None This event is triggered when the map center property changes.
click MouseEvent This event is triggered when the user clicks on the map (but not on a marker or info window).
dblclick MouseEvent This event is triggered when the user double-clicks on the map. Note that a click event is also triggered before this event.
drag None This event is triggered repeatedly while the user drags the map.
dragend None This event is triggered when the user stops dragging the map.
dragstart None This event is triggered when the user starts dragging the map.
heading_changed None This event is triggered when the map heading property changes.
idle None This event is triggered when the map becomes idle after panning or zooming.
maptypeid_changed None This event is triggered when the mapTypeId property changes.
mousemove MouseEvent This event is triggered whenever the user's mouse moves over the map container.
mouseout MouseEvent This event is triggered when the user's mouse exits the map container.
mouseover MouseEvent This event is triggered when the user's mouse enters the map container.
projection_changed None This event is triggered when the projection changes.
resize None This event is triggered when the map (div) changes size.
rightclick MouseEvent This event is triggered when the user right-clicks on the map.
tilesloaded None This event is triggered when the visible tiles finish loading.
tilt_changed None This event is triggered when the map tilt property changes.
zoom_changed None This event is triggered when the map zoom property changes.
other extensions