eschwartz / backbone.googlemaps

A Backbone JS extension for interacting with the Google Maps API (v3.10)
MIT License
139 stars 55 forks source link

Ability to update markerview's position on map #4

Closed Lordnibbler closed 11 years ago

Lordnibbler commented 11 years ago

When adding a new "location" in my application, my server-side app asynchronously geocodes the address with longitude and latitude, and then fires a change:lat listener. As such, the markerview gets added somewhere out in Africa.

Right now, there's no way to refresh a single markerview's position on the map, so I'm forced to .addChild() the same location a second time to the map, which produces undesirable behavior.

Can we set up a way to refresh any single markerview's position on the map whenever longitude or latitude change?

eschwartz commented 11 years ago

A "change:lat" and "change:lng" event should fire on the MarkerView's model when the location changes. You could bind that event to a method that sets the position of the gOverlay object.

The Backbone.GoogleMaps library should be updated to bind changes in a Location to a MarkerView. It would look something like...

In the MarkerView

constructor:  function(){
  // ...
  this.model.on("change", this.refreshOverlay, this);
  // ...
}

// ...

refreshOverlay: function() {
  this.gOverlay.setOptions({
    position: this.model.getLatlng(),
    // ...other overlay options...
  });
}

I don't have a lot of time to mess around with this right now, but if you'd like to submit a pull request, I'll take a look at it.