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

后端 未结 4 1165
情歌与酒
情歌与酒 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:38

    Google has fixed this: http://code.google.com/p/gmaps-api-issues/issues/detail?id=2404

    You can see the fix in action at http://www.publicgloucester.com/test2.html. Ignore the comment that says "it doesn't do what I want"; that comment is obsolete.

    0 讨论(0)
  • 2021-02-04 06:45

    use dragend instead of drag. the code will be,

      google.maps.event.addListener(marker, "dragend", function(event) {
    
           var point = marker.getPosition();
           map.panTo(point);
    
            });
    
    0 讨论(0)
  • 2021-02-04 06:53

    have you tried to implement this to get the bouncy action back? http://groups.google.com/group/nycjs/browse_thread/thread/259a325fa980e575

    0 讨论(0)
  • 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);
    });
    
    0 讨论(0)
提交回复
热议问题