Updating infowindow location in real time

145 views
Skip to first unread message

Jason

unread,
Aug 7, 2012, 9:30:30 AM8/7/12
to google-map...@googlegroups.com
I have a set of draggable markers on a map.  Getting the coordinate information is no issue, but I'd like to have the coordinate location update in the infowindow in real time.

Is there a way to do this without creating multiple InfoWindows?

My current solution is to implement a drag listener for the marker and create a new InfoWindow object when the event fires.  Needless to say, this is very inefficient.

//anonymous function for event listeners
      (function(newMarker){
        google.maps.event.addListener(newMarker, "click", function(){
          infowindow = new google.maps.InfoWindow({
            content: infoWindowData(newMarker, newMarker.title)
          });
         
          infowindow.open(map, newMarker)
        });
       
        google.maps.event.addListener(newMarker, 'dragend', function(){
          //log.info(newMarker.getPosition());
          console.log(newMarker.getPosition());
          newMarker.animation;
          currentMarker = newMarker;
          infowindow = new google.maps.InfoWindow({content: infoWindowData(newMarker, newMarker.title)});
          infowindow.open(map, currentMarker);
        }); 
       
        //listen for the rightclick event to close the infowindow
        google.maps.event.addListener(newMarker, 'rightclick', function(){
          infowindow.close();
          currentMarker = null;
        });
       
        google.maps.event.addListener(newMarker, 'drag', function(){
          var data = infoWindowData(newMarker, newMarker.title);
          console.log("Window Data: "+data);
          infowindow = new google.maps.InfoWindow({content: data});
          infowindow.open(map, newMarker);
         
        });
       
      })(newMarker);

Reply all
Reply to author
Forward
0 new messages