How to get the current zoomLevel

Again it's not a direct way and the documentation looks quite complex, for simplification I had created a small sample.

So basically in our Navigation example - https://github.com/heremaps/here-sdk-examples/blob/master/examples/latest/navigate/android/Java/Navigation/app/src/main/java/com/here/navigation/App.java, please modify the App.java class like this:

package com.here.navigation;

import android.content.Context;

import android.os.Handler;

import android.os.Looper;

import android.util.Log;

import android.widget.TextView;

import androidx.appcompat.app.AlertDialog;

import com.here.sdk.core.Color;

import com.here.sdk.core.GeoCoordinates;

import com.here.sdk.core.GeoPolyline;

import com.here.sdk.core.Location;

import com.here.sdk.gestures.GestureState;

import com.here.sdk.mapview.MapImage;

import com.here.sdk.mapview.MapImageFactory;

import com.here.sdk.mapview.MapMarker;

import com.here.sdk.mapview.MapMeasure;

import com.here.sdk.mapview.MapPolyline;

import com.here.sdk.mapview.MapView;

import com.here.sdk.routing.Route;

import com.here.sdk.routing.Waypoint;

import java.util.ArrayList;

import java.util.List;

import java.util.Locale;




public class App {




    // ... (Other fields remain unchanged)




    private double previousZoomLevel = -1; // Initialize with an invalid value




    public App(Context context, MapView mapView, TextView messageView) {

        // ... (Initialization code remains unchanged)




        handler.post(zoomLevelLogger);




        // ... (Rest of the constructor remains unchanged)

    }




    private Handler handler = new Handler(Looper.getMainLooper());

    private Runnable zoomLevelLogger = new Runnable() {

        @Override

        public void run() {

            double currentZoomLevel = mapView.getCamera().getState().zoomLevel;

            if (previousZoomLevel != currentZoomLevel) {

                Log.d("MapZoomLevel", "Current Zoom Level: " + currentZoomLevel);

                previousZoomLevel = currentZoomLevel;

            }

            handler.postDelayed(this, 1000); // Check zoom level every second

        }

    };




    // ... (Rest of the class remains unchanged)

}



You will be able to log the current zoom level now.




Another way to achieve the above result:

import com.here.sdk.mapview.MapCamera;

import com.here.sdk.mapview.MapCameraListener;

public class App implements MapCameraListener {

    // ... (rest of your fields and methods)




    @Override

    public void onMapCameraUpdated(@NonNull MapCamera.State cameraState) {

        double currentZoomLevel = cameraState.zoomLevel;

        if (previousZoomLevel != currentZoomLevel) {

            Log.d("MapZoomLevel", "Current Zoom Level: " + currentZoomLevel);

            previousZoomLevel = currentZoomLevel;

        }

    }




    public App(Context context, MapView mapView, TextView messageView) {

        // ... (rest of your constructor code)

        mapView.getCamera().addListener(this);

    }

    public void detach() {

        // ... (rest of your detach method code)

        mapView.getCamera().removeListener(this);

    }

}