谷歌地图API - 双击地图上的点以在那里移动标记

时间:2014-11-06 18:42:34

标签: google-maps marker double-click

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

2 个答案:

答案 0 :(得分:3)

(编辑:看看Vinks'发布。他指出Google地图有一个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>

答案 1 :(得分:1)

我无法评论Emmanuel Delay的答案,但为了纠正stopPropagation问题,您必须使用Maps API的disableDoubleClick选项。

以下是更新后的结果:

@Autowired
private ProcessEngine processEngine;