Google Maps Chi...LOGIN
Google Maps Chinese API Manual
author:php.cn  update time:2022-04-14 16:36:56

Map API Map() constructor



Instance

Create a Google Map:

<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>

<script>
function initialize()
{
var mapOpt = {
  center:new google.maps.LatLng(51.508742,-0.120850),
  zoom:5,
  mapTypeId:google.maps.MapTypeId.ROADMAP
  };
var map=new google.maps.Map(document.getElementById("googleMap"),mapOpt);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
<div id="googleMap" style="width:500px;height:380px;"></div>

</body>
</html>

Run Instance»

Click the "Run Example" button to view the online example


Definition and usage

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


Syntax

new google.maps.Map(HTMLElement,MapOptions)

Parameter value

ParameterDescription
HTMLElementSpecifies which HTML element the map should be placed in.
MapOptionsA MapOptions object with map initialization variables/options.

Map() method

## setHeading(NoneSet the compass direction (measured in degrees) of the aerial image, with the cardinal direction being north. setMapTypeId(NoneChange the map type to be displayed. setOptions(None## setStreetView(StreetViewPanoramasetTilt(numbersetZoom(number

Properties of Map()

MethodReturn valueDescription
fitBounds(LatLngBounds)NoneSets 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()NodeReturns 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 TERRAINReturns the current map type.
getProjection()ProjectionReturns the current Projection.
getStreetView()StreetViewPanoramaReturns the default StreetViewPanorama bound to the map.
getTilt()numberReturns the incident angle number of the aerial image (supports SATELLITE and HYBRID map types).
getZoom()#numberReturns the current zoom level of the map.
panBy(xnumber,ynumber)NoneChanges the center of the map by the given distance in pixels.
panTo(LatLng)NoneChanges 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
number)
MapTypeId)
MapOptions)
)NoneBind a StreetViewPanorama to the map.
)NoneSet the incident angle number of aerial images (supports SATELLITE and HYBRID map types) .
)None
##PropertiesTypeDescription## controlsArray.<MVCArray.<Node>>mapTypesMapTypeRegistryoverlayMapTypesMVCArray.<MapType>

Events of Map()

Additional controls to attach to the map.
A registry of MapType instances by string ID.
Additional map types to overlay.
##EventParametersDescription## bounds_changedcenter_changedclickMouseEventdblclickMouseEventdragdragenddragstartheading_changedidlemaptypeid_changedmousemoveMouseEventmouseoutMouseEventmouseoverMouseEventprojection_changedresizerightclickMouseEventtilesloadedtilt_changedzoom_changed
NoneThis event is triggered when the visual area range changes.
NoneThis event is triggered when the map center property changes.
This event is fired when the user clicks on the map (but not on the marker or info window) .
This event is triggered when the user double-clicks the map. Note that the click event is also fired before this event is fired.
NoneThis event will be triggered repeatedly when the user drags the map.
NoneThis event is triggered when the user stops dragging the map.
NoneThis event is fired when the user starts dragging the map.
NoneThis event is triggered when the map heading property changes.
NoneThis event is fired when the map becomes idle after panning or zooming.
NoneThis event is triggered when the mapTypeId property changes.
This event is triggered whenever the user's mouse moves over the map container.
This event is triggered when the user's mouse exits from the map container.
This event is triggered when the user's mouse enters the map container.
NoneThis event is fired when the projection changes.
NoneThis event is triggered when the map (div) changes size.
This event is triggered when the user right-clicks on the map.
NoneThis event will be triggered when the visible tiles are loaded.
NoneThis event is triggered when the map tilt property changes.
NoneThis event is triggered when the map zoom property changes.