自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Google Maps API簡(jiǎn)易教程(二)

開發(fā) 開發(fā)工具
單擊一下Marker,就會(huì)觸發(fā)click事件。拖曳當(dāng)前地圖,將會(huì)觸發(fā)center_changed事件。而google.maps.addListener監(jiān)聽(tīng)地圖上每一個(gè)動(dòng)作。

 一、Google Map Event

    單擊一下Marker,就會(huì)觸發(fā)click事件。拖曳當(dāng)前地圖,將會(huì)觸發(fā)center_changed事件。而google.maps.addListener監(jiān)聽(tīng)地圖上每一個(gè)動(dòng)作,

相應(yīng)的事件處理代碼由用戶編寫。一下舉幾個(gè)例子,以加深理解。

  (1)單擊Marker改變Zoom

     如上圖所示,單擊London上的Marker,當(dāng)前的地圖的Zoom改變,相應(yīng)的代碼如下:

 

  1. // Zoom to 9 when clicking on marker 
  2. google.maps.event.addListener(marker,'click',function() { 
  3.   map.setZoom(9); 
  4.   map.setCenter(marker.getPosition()); 
  5.   }); 

  (2)Pan返回Marker

    在本例中,單擊地圖左上角的pan的一個(gè)角,地圖的中心發(fā)生了改變,3秒后又返回到原來(lái)的中心,這將會(huì)觸發(fā)center_changed事件。相應(yīng)的代碼如下:

 

  1.  google.maps.event.addListener(map,'center_changed',function() { 
  2.   window.setTimeout(function() { 
  3.     map.panTo(marker.getPosition()); 
  4.   },3000); 
  5. }); 

  (3)單擊Marker顯示InfoWindow

     如上圖,單擊Marker,顯示一個(gè)含有Hello world 字符的InfoWindow,相關(guān)代碼如下:

 

  1. var infowindow = new google.maps.InfoWindow({ 
  2.   content:"Hello World!" 
  3.   }); 
  4.  
  5. google.maps.event.addListener(marker, 'click', function() { 
  6.   infowindow.open(map,marker); 
  7.   }); 

 (4)設(shè)置Markers,并為每一個(gè)Marker打開一個(gè)InfoWindow

   相關(guān)代碼如下:

 

  1. google.maps.event.addListener(map, 'click', function(event) { 
  2. placeMarker(event.latLng); 
  3. }); 
  4.  
  5. nction placeMarker(location) { 
  6. var marker = new google.maps.Marker({ 
  7.   position: location, 
  8.   map: map, 
  9. }); 
  10. var infowindow = new google.maps.InfoWindow({ 
  11.   content: 'Latitude: ' + location.lat() + 
  12.   '<br>Longitude: ' + location.lng() 
  13. }); 
  14. infowindow.open(map,marker); 

        以上只是幾個(gè)Event處理的簡(jiǎn)單應(yīng)用,還有其他的常見(jiàn)事件,比如MapsEventListener,MouseEvent等等,在這里不再細(xì)講。如果有興趣的話,請(qǐng)查閱相關(guān)文檔。

原文鏈接:http://www.cnblogs.com/williamcai/archive/2013/03/01/2937933.html

責(zé)任編輯:彭凡 來(lái)源: 博客園
相關(guān)推薦

2013-02-28 13:35:02

Google Maps

2013-06-06 13:35:33

Google Maps

2013-01-08 17:30:31

Google MapsAndroid MapMapFragment

2010-11-02 14:31:44

Google Maps

2011-12-02 09:59:29

API

2012-05-13 13:55:04

蘋果

2013-05-20 16:42:13

GoogleGoogle Maps

2010-05-21 15:46:41

Google Code

2011-04-18 10:52:17

Jpcap

2011-11-02 17:31:58

Maps API

2011-10-27 11:32:36

Google云計(jì)算SQL數(shù)據(jù)庫(kù)

2012-05-09 11:56:28

RIM

2009-07-24 09:26:27

Google Maps

2010-06-30 10:46:20

Linux SNMP安

2010-05-21 12:27:22

SVN使用教程

2015-01-14 09:46:52

Google API

2009-04-22 17:16:50

Analytics AGoogle測(cè)試

2015-03-18 10:58:27

Google Now API

2009-01-04 09:16:11

google Read開發(fā)APIGoogle API

2021-08-04 10:36:34

git項(xiàng)目開發(fā)
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)