Get map center point on scrolling Google maps v2 in android?
You can use:-
myMap.setOnCameraChangedListener(this);
And in the listener:-
onCameraChange(CameraPosition position) {
LatLng target = position.target;
// do what you need with the position here
}
I'm not sure about the index out of bounds. But to set a default map position you could use something like below:-
private void setDefaultMapPosition(LatLng latLng) {
CameraPosition camPos =
new CameraPosition.Builder().target(latLng)
.zoom(A_DEFAULT_MAP_ZOOM)
.bearing(0)
.tilt(0)
.build();
myMap.moveCamera(
CameraUpdateFactory.newCameraPosition(camPos));
}
The interface OnCameraChangeListener
has been deprecated. You can now use now OnCameraIdleListener
Called when camera movement has ended, there are no pending animations and the user has stopped interacting with the map.
and fetch the coordinates of the center by doing:
val centerCoordinates = mMap.cameraPosition.target