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 );
}
});