Maps API Map() Constructor
Example
Create a Google Map:
var map=new google.maps.Map(document.getElementById("googleMap"),mapOpt);
Try it »
Definition and Usage
The Map() constructor creates a new map and inserts it into the specified HTML element (
element).
Syntax
new google.maps.Map(
HTMLElement
,
MapOptions
)
Parameter value
| Parameters | Description |
|---|---|
| HTMLElement | Specifies which HTML element to place the map in. |
| MapOptions | A MapOptions object with map initialization variables/options. |
Methods of Map()
| 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 center of the map. |
| getDiv() | Node | Returns the DOM object containing the map. |
| getHeading() | number | Returns the compass heading of the aerial image (supports 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 incidence angle in degrees of the aerial image (supports 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 a given distance measured in pixels. |
| panTo(LatLng) | None | Changes the center of the map to the given LatLng. |
| panToBounds(LatLngBounds) | None | Pans the map the minimum distance required to contain the given LatLngBounds. |
| setCenter(LatLng) | None | |
| setHeading(number) | None | Sets the compass direction of the aerial image (measured in degrees), with north as the basic 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 incidence angle in degrees of the aerial image (supports SATELLITE and HYBRID map types). |
| setZoom(number) | None |
Properties of Map()
| property | Type | Description |
|---|---|---|
| controls | Array. |
Extra controls to attach to the map. |
| mapTypes | MapTypeRegistry | A registry of MapType instances divided by string ID. |
| overlayMapTypes | MVCArray. |
Extra map types to overlay. |
Events of Map()
| Events | Parameters | Description |
|---|---|---|
| bounds_changed | None | This event is triggered when the visible area range changes. |
| center_changed | None | This event is triggered when the map center property changes. |
| click | MouseEvent | This event is triggered when the user clicks the map (but not when clicking a marker or info window). |
| dblclick | MouseEvent | This event is triggered when the user double-clicks the map. Note that a click event is also triggered before this event. |
| drag | None | This event is triggered repeatedly when 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 the map. |
| tilesloaded | None | This event is triggered when the visible tiles have finished 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. |