2010-06-08 98 views
3

我注意到,在大多數Google地圖中,您不能將標記圖標拖動到地址欄中,並查看或下載圖標.png文件本身。相反,你將光標懸停在標記上,你可以看到javascript:void(0)。谷歌地圖,如何禁用標記圖標被拖動?

這是如何實現的?謝謝!

+0

http://code.google.com/intl/es-ES/apis/maps/documentation/javascript/basics.html – Ben 2010-06-08 18:10:27

回答

1

它看起來像v3 API中的標記不能被拖動到地址欄,而v2 API中的標記可以。

以下v3示例不允許標記移動(在Firefox和Chrome中進行測試)。它還顯示javascript:void(0)在狀態欄:

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>Google Maps API No Marker Dragging v3</title> 
    <script src="http://maps.google.com/maps/api/js?sensor=false" 
      type="text/javascript"></script> 
</head> 
<body> 
    <div id="map" style="width: 500px; height: 400px;"></div> 

    <script type="text/javascript"> 
    var map = new google.maps.Map(document.getElementById('map'), { 
     zoom: 2, 
     center: new google.maps.LatLng(35.00, -25.00), 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }); 

    new google.maps.Marker({ 
     position: map.getCenter(), 
     map: map 
    }); 

    </script> 
</body> 
</html> 

截圖:

Google Maps API No Marker Dragging v3 http://img339.imageshack.us/img339/570/nodrag.jpg

在另一方面,使用第2版API相同的例子,使得標記被拖動到地址欄:

<!DOCTYPE html> 
<html> 
<head> 
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> 
    <title>Google Maps API No Marker Dragging v2</title> 
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false" 
      type="text/javascript"></script> 
</head> 
<body onunload="GUnload()"> 
    <div id="map" style="width: 500px; height: 400px;"></div> 

    <script type="text/javascript"> 
    var map = new GMap2(document.getElementById("map")); 
    map.setCenter(new GLatLng(35.00, -25.00), 2); 
    map.addOverlay(new GMarker(map.getCenter())); 
    </script> 
</body> 
</html> 

截圖:

+0

@勞倫斯:感謝您的編輯:) – 2010-06-08 18:49:20