Google Earth For Javascript 谷歌地球添加標記

//前提是google earth 已經在頁面加載   即 ge!= null 否則報錯

function addMarker(lng,lat,markerName,markerIconUrl,description) 

//lng, lat爲double 經緯度

//markerName爲string標記旁顯示的文本, markerIconUrl爲自定義圖標的url地址如:Http://www.aa.com/images/bb.png

//description標記的說明文字

{
 var point = ge.createPoint('');
 point.setLongitude(lng);
 point.setLatitude(lat);
 var placemark = ge.createPlacemark('');
 placemark.setDescription(description);
 placemark.setName(markerName);
 
 // Define a custom icon.
 var icon = ge.createIcon('');

 icon.setHref(markerIconUrl);
 var style = ge.createStyle(''); //create a new style
 style.getIconStyle().setIcon(icon); //apply the icon to the style
 placemark.setStyleSelector(style); //apply the style to the placemark
 
 
 placemark.setGeometry(point);
 ge.getFeatures().appendChild(placemark);
 google.earth.addEventListener(placemark, 'click', onMarkerClick); //如果需要則添加placemark的鼠標單擊響應
}

 

function onMarkerClick(event)  // placemark的鼠標單擊響應
   {
      event.preventDefault();  //使默認的響應失效
      ////Do sth.

   }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章