0

When you long click on a draggable marker, the marker moves up and allows you to move it. My problem is that I can't see the bottom of the marker because my finger is on top of it. I'm trying to accurately position the bottom middle of the marker icon.

A simple fix would be to control the offset of how much the marker moves up when dragging. I would make this offset large enough so you could see the bottom of the marker above your finger.

I tried manually pre-offsetting the marker in dragstart, but as soon as you start moving the marker, it goes right back to the original offset.

Michael
  • 1,889
  • 2
  • 11
  • 6

2 Answers2

0

This is not currently possible. The offset is hardcoded in the API.

I suggest posting a feature request on gmaps-api-issues.

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
0

I've found a workaround for this issue that works like a charm at least for me. The idea: Set the anchor point of the icon of the marker the desired amount of millimeters/inches below the icon. This moves up the icon to the preferred position. But doing so, you have to offset the latitude of the marker by the appropriate amount of degrees. The formula I use to calculate degrees from millimeters works for all locations and zoom levels of the map, but the constant factor (80) depends on the size of the icon you use, of course on your anchor point, and most probably on the resolution of the device. For me, this code does the job on my Galaxy S9:

mMap.setOnMarkerDragListener(new GoogleMap.OnMarkerDragListener() {
  @Override public void onMarkerDragStart(Marker marker) {
    marker.setAnchor(0.5f, 1.4f);
    VisibleRegion vR = mMap.getProjection().getVisibleRegion();
    View v = findViewById(R.id.map);
    offset = 80*(vR.latLngBounds.northeast.latitude - vR.latLngBounds.southwest.latitude)/v.getLayoutParams().height;
  }
  @Override public void onMarkerDrag(Marker marker) {
    // Your code. Replace all 'marker.getPosition()' by 'new LatLng(marker.getPosition().latitude + offset, marker.getPosition().longitude)'   
  }
  @Override public void onMarkerDragEnd(Marker marker) {
    // Your code.
  }
});
desperate
  • 1
  • 3