Skip to content

How to fetch new location after the marker is drag to another position #8

Closed
hrbg opened this Issue Mar 7, 2012 · 2 comments

2 participants

@hrbg
hrbg commented Mar 7, 2012

Hi @tristandunn

Great plugin, really easy to implement

I found a way to drag the marker after the map is rendered thanks to this post http://dailyjs.com/2012/02/21/jquery-roundup/
What I'm not able to do is to grab the new location values after the marker is moved. Is there a event to bind this action ?

Thanks

@tristandunn
Owner

The library itself doesn't support any sort of dragging events, but since you have access to the Google Maps objects it should be fairly easy to do. I have not tested this out, but based on the documentation it should be something like:

$("#location")
  .autoGeocoder()
  .bind("auto-geocoder.onGeocodeResult", function() {
    var marker = this.marker;

    marker.setDraggable(true);

    google.maps.event.addListener(marker, "position_changed", function() {
      var position = marker.getPosition();
    });
  });

Check out the API and Event references.

Also, note that I reuse the marker, so you may want to bind to another event or keep track of your event binding to avoid multiple listeners. And that the position_changed event is likely to be triggered by the input changing the position as well.

@hrbg
hrbg commented Mar 8, 2012

Thanks for your response.

I'll try this approach

@hrbg hrbg closed this Mar 8, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.