google-maps - Google Maps API - 双击 map 上的点以将标记移动到那里

标签 google-maps marker double-click

google maps API 中是否有内置选项或实现此功能的简单方法。我想双击 map 上的一个点,让谷歌地图将我的标记移动到那个点。

最佳答案

(编辑:查看 Vinks 的帖子。他指出 Google map 有一个 disableDoubleClickZoom 选项。)

当然

<!DOCTYPE html>
<html>
  <head>
    <title>Double click on the map</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body, #map-canvas {
        height: 500px;
        margin: 0px;
        padding: 0px
      }

    </style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
    <script>
    function initialize() {
      var my_position = new google.maps.LatLng(50.5, 4.5);
      var map = new google.maps.Map(document.getElementById('map-canvas'), {
        center: my_position,
        zoom: 15
      });
      var marker = new google.maps.Marker({
        position: my_position,
        map: map
      });
      // double click event
      google.maps.event.addListener(map, 'dblclick', function(e) {
        var positionDoubleclick = e.latLng;
        marker.setPosition(positionDoubleclick);
        // if you don't do this, the map will zoom in
        e.stopPropagation();
      });
    }
    google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head>
  <body>
    <div id="map-canvas"></div>
    <p>Double click on the map</p>
  </body>
</html>

关于google-maps - Google Maps API - 双击 map 上的点以将标记移动到那里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26787022/

相关文章:

javascript - 如何使用 Google Maps API 在标记上设置弹出窗口?

android - 在 Maps API v2 中完全禁用 onMarkerClickListener

android - 为什么 android onLongPress 总是在 onDoubleTap 之后触发?

javascript - Google 地点自动完成 - 某些建议的地址未以英文显示

google-maps - 从地理编码器结果获取城市?

javascript - Google map API Javascript 和跟随标记

javascript - map 拖尾后如何获取经纬度

excel - 单击单元格时运行一个宏,双击单元格时运行另一个宏

objective-c - 使用 CGEventCreateMouseEvent() 执行双击

java - getLastLocation().addOnSuccessListener 在按钮中不起作用