简体   繁体   English

谷歌地图,如何禁止拖动标记图标?

[英]google maps, how to disable marker icons from being dragged around?

I have noticed that in most google maps you can not drag the marker icon into your address bar and see or download the icon .png file itself. 我注意到在大多数谷歌地图中,​​您无法将标记图标拖到地址栏中,并查看或下载图标.png文件本身。 Rather then you hover your cursor over the marker, you can see javascript:void(0). 而不是将光标悬停在标记上,您可以看到javascript:void(0)。

How is that achieved? 这是如何实现的? Thanks! 谢谢!

It looks like markers in the v3 API cannot be dragged to the address bar, while markers in the v2 API can. 看起来v3 API中的标记无法拖动到地址栏,而v2 API中的标记可以。

The following v3 example does not allow the marker to move around (tested in Firefox and Chrome). 以下v3示例不允许标记移动(在Firefox和Chrome中测试)。 It also shows javascript:void(0) in the status bar: 它还在状态栏中显示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>

Screenshot: 截图:

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

On the other hand, the same example using the v2 API, allows the marker to be dragged to the address bar: 另一方面,使用v2 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>

Screenshot: 截图:

Google Maps API No Marker Dragging v2 http://img39.imageshack.us/img39/8330/yesdrag.jpg Google Maps API No Marker Dragging v2 http://img39.imageshack.us/img39/8330/yesdrag.jpg

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM