Introduction to GoogleMapapiv2 Functions

Source: Internet
Author: User
Functioninitialize () {GBrowserIsCompatible () generally, you must first determine whether the browser supports Googlemaps execution if (GBrowserIsCompatible () {varlatlngnewGLatLng (39.9493, 116.3975); Set coordinates to specify a container div for map, the second parameter sets some of its options. This parameter is

Function initialize () {// GBrowserIsCompatible () generally, you must first determine whether the browser supports Google maps execution if (GBrowserIsCompatible () {var latlng = new GLatLng (39.9493, 116.3975 ); // Set coordinates // specify a container p for map, and set some options for the second parameter. this parameter is

Function initialize (){
// GBrowserIsCompatible () generally, you must first determine whether the browser supports Google maps execution.
If (GBrowserIsCompatible ()){
Var latlng = new GLatLng (39.9493, 116.3975); // Set coordinates
// Specify a container p for map, and set some options for the second parameter. this parameter is an object. For details about the attributes, see Google map API.
Var map = new GMap2 (document. getElementById ("map_canvas"), {size: new GSize (500,300), backgroundColor: "white "});
Map. enableScrollWheelZoom (); // you can set the zoom of a map to be controlled by the mouse wheel (by default, the Zoom is not rolled ).
Map. setCenter (latlng, 13); // set the center of the map to the coordinate point, and 13 to the zoom level (0-19; 0 to see the whole world, 19 to see the independent buildings)

Var blueIcon = new GIcon (G_DEFAULT_ICON); // define a marked image
// BlueIcon. image = "http://www.google.cn/intl/en_us/mapfiles/ MS/micons/blue-dot.png ";
BlueIcon. image = "http://labs.google.com/ridefinder/images/mm_20_red.png"; // Tagged image Style
// BlueIcon. shadow = "http://labs.google.com/ridefinder/images/mm_20_shadow.png"; shadow Image
// BlueIcon. iconSize = new GSize (30, 30 );
// BlueIcon. shadowSize = new GSize (); remove the shadow marked with the image

// A flag on the map. draggable: You can drag the flag. bouncy: sets whether the flag will bounce when it falls. (for other attributes, see Google map API)
Var marker = new GMarker (latlng, {icon: blueIcon, draggable: true, bouncy: false });
Map. addOverlay (marker); // Add the mark to the map.

// Process the tag or map event (The following is the tag processing)
GEvent. addListener (marker, "click", function (){
Map. setZoom (17); // sets the zoom degree of the map.
Marker. openInfoWindowHtml ("this is the location of positioning"); // display information window in the form of a text balloon
// Map. openInfoWindowHtml (latlng, "this is the location of positioning"); the text balloon above can also be displayed in this way
});

/*
If a map click occurs on the stack layer, the GMap2 click event will pass the overlay and overlaylatlng (GLatLng ),
Otherwise, it will only pass the latlng of the map coordinate.
*/
GEvent. addListener (map, "click", function (overlay, latlng ){
If (latlng ){
Var str = "coordinates:" + latlng. lat () + "," + latlng. lng () + ",
Zoom level: "+ map. getZoom
() + "";
Map. clearOverlays (); // clear all tags
Map. addOverlay (new GMarker (latlng ));
Map. openInfoWindowHtml (latlng, str );
}
});
}
}

Map. enableScrollWheelZoom (); // you can set the zoom of a map to be controlled by the mouse wheel (not by default ).
// Map. disableScrollWheelZoom (); sets that the map cannot be scaled by the mouse wheel (default ).
// Map. enableDoubleClickZoom (); you can double-click to zoom in the map, double-click to zoom in, and right-click to zoom out (default ).
// Map. disableDoubleClickZoom (); double-click Zoom is prohibited.
// Map. disableDragging (); Do not drag a map to a new location.
// Map. setMapType (G_SATELLITE_MAP); directly sets the map Display format (for example, satellite display)
/*
There are four standard map types (the fourth type does not know what it means ):
• G_NORMAL_MAP-default view
• G_SATELLITE_MAP-display Google Earth satellite images
• G_HYBRID_MAP-hybrid display of common and satellite views
• G_DEFAULT_MAP_TYPES-these three types of arrays are useful when repeated processing is required.
*/

The following shows how to add a widget.
Map. addControl (new GLargeMapControl (); // large PAN/zoom controls used on Google Maps
// Map. addControl (new GSmallMapControl (); a smaller PAN/zoom control used on Google Maps
Map. addControl (new GMapTypeControl (); // you can call this button to change the map type (for example, map and satellite ).
Map. addControl (new GScaleControl (), new GControlPosition (G_ANCHOR_BOTTOM_RIGHT, new GSize (5, 20); // display the map scale
// The foldable Overview map located in the corner of the screen. The position is set through GControlPosition [all controls can be set. I found that it is still in the default position at the beginning.
In the lower-right corner of the page, When you click zoom in, it will run to the location you specified (very depressing). There is no problem with other controls.],
// Map. addControl (new GOverviewMapControl (), new GControlPosition (G_ANCHOR_BOTTOM_LEFT, new GSize (30,30 )));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.