Google maps, how to disable marker icons from drag and drop?

I noticed that on most Google maps you can’t drag the marker icon into your address bar and see or download the .png file itself. Instead, you hover over the marker, you can see javascript: void (0).

How is this achieved? Thank!

+3
source share
1 answer

It seems that tokens in the v3 API cannot be dragged into the address bar, but tokens in the v2 API can.

The following v3 example does not allow the marker to move (tested in Firefox and Chrome). It also shows javascript:void(0)in the status bar:

<!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:

API Google v3 http://img339.imageshack.us/img339/570/nodrag.jpg

, API v2 :

<!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>

:

API Google v2 http://img39.imageshack.us/img39/8330/yesdrag.jpg

+1

Source: https://habr.com/ru/post/1749074/


All Articles