Skip to content

Drag and Drop Markers to edit position ? #3289

Answered by jnorvell
jnorvell asked this question in Q&A
Discussion options

You must be logged in to vote

I was able to get it to work using a couple of pieces:

  1. In the code where you create your <Marker> elements, add the draggable={true} property.
  2. Add the ref={} property, and notice how we can use the callback handler form, this way it passes the React component as the node parameter, and we can get a handle to the google maps Marker by referencing the .marker property.
  3. To the google maps marker, we add an dragend event listener.
  4. When the dragend event listener fires, we can get the new latitude-longitude position by calling .getPosition() and then lat() and lng() to get the new values.
  5. In my code, I then make a REST API call to my own backend to persist the location's new position.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by jnorvell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant