In Google Maps V3, how can I get a draggable marker to pan the map?

后端 未结 4 1176
情歌与酒
情歌与酒 2021-02-04 06:20

I have found several V2 examples of how to pan the map while a marker is being dragged. For example: http://www.putyourlightson.net/projects/coordinates

    //         


        
4条回答
  •  长发绾君心
    2021-02-04 06:59

    The event you want to listen is the one used in your example "drag", what you can do to make it look less "bogus" is add a delay, so the maps follows the marker instead of being immediately updated. Try this:

    google.maps.event.addListener(marker, "drag", function(event) {
      var point = marker.getPosition();
      window.setTimeout(function(){
        map.panTo(point);
      }, 100);
    });
    

提交回复
热议问题