Davide3i Davide3i - 1 year ago 663
Android Question

OnCameraChangeListener() is deprecated

Today, looking back to my old code, I've found out that OnCameraChangeListener() is now deprecated.

I'm finding difficult to understand how to fix this piece of code of mine:

mGoogleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {
public void onCameraChange(CameraPosition cameraPosition) {
// Cleaning all the markers.
if (mGoogleMap != null) {

mPosition = cameraPosition.target;
mZoom = cameraPosition.zoom;

if (mTimerIsRunning) {

mTimerIsRunning = true;

The new listener (aka OnCameraMoveListener()) method onCameraMove() doesn't have a CameraPosition cameraPosition input variable, so I'm pretty lost: is there a way to recycle my old code?

Here some references.

Thank you for your help.

Answer Source

In the new model for camera change events, you are correct that the CameraPosition is not passed into the listener.

Instead, you should just use getCameraPosition() whenever you specifically need it (i.e., when the move starts, mid-move, canceled, or finished/returned to idle).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download