Android: Drag map while keeping marker at the center
Try at first this layout for your Activity_map.xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="@drawable/gps"
/>
</RelativeLayout>
Having a map under an ImageView with your marker icon would be the best way to go here (just a framelayout with your map fragment under and your marker image centered on top should work). Then you can use an OnCameraIdleListener
which would receive a callback when the map movement has ended. So just set an instance of OnCameraIdleListener
to your map to listen for movement callbacks like so:
map.setOnCameraIdleListener(new GoogleMap.OnCameraIdleListener() {
@Override
public void onCameraIdle() {
//get latlng at the center by calling
LatLng midLatLng = map.getCameraPosition().target;
}
});