2

I create a marker and place it on the map on a long press. The only problem that I have is that I have to lift up my finger, long press the marker again (though I really didn't press the marker the first time it was actually the map), and then I am able to drag it. This is the default functionality and it works fine.

What I would prefer is to be able to start dragging on the first long press of the map when I lay my marker down. I am wondering if there is some way to manually fire the drag event where the marker snaps to my finger position as soon as it is created and then can be dragged and placed where I want it.

Here is the relevant code, thanks!

GoogleMap gMap;

@Override
public void onMapLongClick(LatLng latLng) {
    MarkerOptions markerOptions = new MarkerOptions().position(latLng)
            .title(null).draggable(true);
    gMap.addMarker(markerOptions);

   //I would like to be able to start dragging the marker here
}
Zach
  • 1,964
  • 2
  • 17
  • 28
  • 1
    Instead of adding the marker right away in the onMapLongClick event, what if you just added a marker icon on the map that follows the coordinates of your finger as you press and drag along the map, then create and place the marker when you stop pressing on the map? I can't think of another way to do it since you'd have to actually place the marker on the map and let go before you can click on the marker and move it. – not_a_bot Jun 15 '15 at 23:31
  • @Zach any hope on the above? – Jenno Richi Benat Jan 04 '18 at 17:11
  • @JennoRichiBenat I ended up making a proof of concept work by adding an overlay over the map. On overlay touch for x ms, add an image under the finger that follows where it drags, and then place a marker on the map (and remove the image) when you lift your finger.. I may be able to dig up the code for it somewhere, I ended up just not implementing it in any production stuff due to the fact that it is tough to tell whether your finger is on an existing marker or if you should be creating a new one, still may look at it in the future though. – Zach Jan 04 '18 at 19:28
  • @JennoRichiBenat worth noting that one workaround for the existing maker issue would be to make the map touch time slightly longer than the timeout of the marker long press for the drag event and cancel the touch event on drag start. Not saying it isn't hacky but I think it would work – Zach Jan 04 '18 at 19:32

1 Answers1

-1

Here's the only promising thing I could find on programmatically triggering an event, see if it works with dragstart. If not, you can check https://code.google.com/p/gmaps-api-issues/ and file a feature request if one doesn't exist already.

Community
  • 1
  • 1
not_a_bot
  • 2,332
  • 2
  • 19
  • 33