Map API Map() Constructor
Example
Create a Google Map:
Definition and Usage
The Map() constructor creates a new map and inserts it into the specified HTML element (a <div> element).
Syntax
Parameter Values
| Parameter | Description |
|---|---|
| HTMLElement | Specifies the HTML element where the map should be placed. |
| MapOptions | A MapOptions object with initialization variables/options for the map. |
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 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 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 amount necessary to contain the given LatLngBounds. | | setCenter(LatLng) | None | | | setHeading(number) | None | Sets the compass heading for aerial imagery (measured in degrees from north). | | 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 for aerial imagery (supported for SATELLITE and HYBRID map types). | | setZoom(number) | None | |
Properties of Map()
| Property | Type | Description |
|---|---|---|
| controls | Array.<MVCArray.<Node>> | Additional controls to attach to the map. |
| mapTypes | MapTypeRegistry | A registry of MapType instances by string ID. |
| overlayMapTypes | MVCArray.<MapType> | Additional map types to overlay. |
Events of Map()
| Event | Parameters | Description |
|---|---|---|
| bounds_changed | None | This event is fired when the viewport bounds change. |
| 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 on a marker or info window). |
| 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. |
| heading_changed | None | This event is fired when the map heading property changes. |
| 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. |
| mousemove | MouseEvent | This event is fired whenever the user's mouse moves over the map container. |
| mouseout | MouseEvent | This event is fired when the user's mouse exits the map container. |
| mouseover | MouseEvent | This event is fired when the user's mouse enters the map container. |
| projection_changed | None | This event is fired when the projection changes. |
| resize | None | This event is fired when the map (div) changes size. |
| rightclick | MouseEvent | This event is fired when the user right-clicks on the map. |
| tilesloaded | None | This event is fired when the visible tiles have finished loading. |
| tilt_changed | None | This event is fired when the map tilt property changes. |
| zoom_changed | None | This event is fired when the map zoom property changes. |