Two easy steps:
Step 1
I used a RelativeLayout as parent of fragment with map and center in it an ImageView (which will do as the centered map marker just like in uber or easy taxi apps):
<!-- Map and ImageView in center for simulating the map marker -->
<RelativeLayout
android:id="@+id/confirm_address_map_wrapper"
android:layout_width="match_parent"
android:layout_height="220dp">
<fragment
android:id="@+id/confirm_address_map_fragment"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
/>
<!-- Image View that acts as map marker notice centerInParent-->
<View
android:id="@+id/view"
android:layout_width="1dp"
android:layout_height="1dp"
android:layout_centerInParent="true"/>
<ImageView
android:id="@+id/confirm_address_map_custom_marker"
android:layout_width="@dimen/ICON_DEFAULT_SIZE"
android:layout_height="@dimen/ICON_DEFAULT_SIZE"
android:layout_above="@+id/view"
android:layout_centerHorizontal="true"
android:src="https://stackoverflow.com/questions/19346206/@mipmap/my_map_marker"/>
</RelativeLayout>
Step 2
onMapReady() method at my activity I use googleMap instance method setOnCameraChangeListener() that lets me listen when the map is used and get latitude and longitude based on the center of camera position:
@Override
public void onMapReady(GoogleMap googleMap) {
googleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition cameraPosition) {
Log.i("centerLat",cameraPosition.target.latitude);
Log.i("centerLong",cameraPosition.target.longitude);
}
});
}
UPDATE:
OnCameraChangeListener is deprecated . Please use OnCameraIdleListener:
[Source: https://stackoverflow.com/a/38732283/421467]