Google Maps API level-1

Source: Internet
Author: User
From: http://hi.baidu.com/xfm_zhr/blog/item/8c1790517e87ea888d54302a.html

1.Googlemaps common events and Application Ideas

When the map is dragged by the mouse, the gmap2 object will trigger events such as dragstart, drag, and dragend.

Example: dynamically display the central position of a map.

//Update information. El indicates the specified HTML element, and info indicates the content displayed in it.

Function updateinfo (El, Info)

{

El. innerhtml = Info;

}

//Add drag event listener

Function adddraglistener ()

{

//Listen to events on the map

Gevent. adddomlistener (MAP, 'dragstart', function ()

{

Updateinfo (eventinfo ,"Current Event: dragstart ");

});

Gevent. adddomlistener (MAP, 'drag', function ()

{

Updateinfo (eventinfo ,"Current Event: Drag ");

Updateinfo (mapcenter ,"Current map center latitude: "+ map. getcenter (). LAT () +" longitude "+ map. getcenter (). LNG ());

});

Gevent. adddomlistener (MAP, 'dragend', function ()

{

Updateinfo (eventinfo ,"Current Event: dragend ");

});

}

Map scaling is a zoomstart and zoomend event triggered by gmap2.

Example: dynamically obtain the map zoom level

//Add scaling event listener

Function addzoomlistener ()

{

//Listen to scaling events on the map

Gevent. adddomlistener (MAP, 'zoomstart', function ()

{

Updateinfo (eventinfo ,"Current Event: zoomstart ");

});

Gevent. adddomlistener (MAP, 'zoomend', function ()

{

Updateinfo (eventinfo ,"Current Event: zoomend ");

Updateinfo (zoomlevel ,"Current map zoom level: "+ map. getzoom ());

});

}

 

When the map type changes, gmap2 will trigger the maptypechanged event.

Example: dynamically obtain the map type.

//Add maptypechanged event listener

Function addmaptypelistener ()

{

//Monitor maptypechanged events on a map

Gevent. adddomlistener (MAP, 'maptypechanged ', function ()

{

Updateinfo (eventinfo ,"Current Event: maptypechanged ");

Updateinfo (maptype ,"Current map type: "+ map. getcurrentmaptype (). getname (false ));

});

}

 

Click Google map. gmap2 will trigger the click event. Note: This event contains two parameters: overlay and point.

Example: Get the mouse position and add a gmarker object.

Gevent. addlistener (MAP, 'click', function (overlay, point)

{

If (point)

{

VaR marker = new gmarker (point );

Map. addoverlay (Marker );

}

});

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.