Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

OnCameraChangeListener vs getCameraPosition #4326

Closed
tobrun opened this issue Mar 15, 2016 · 3 comments
Closed

OnCameraChangeListener vs getCameraPosition #4326

tobrun opened this issue Mar 15, 2016 · 3 comments
Assignees
Labels
Android Mapbox Maps SDK for Android bug

Comments

@tobrun
Copy link
Member

tobrun commented Mar 15, 2016

A user reported this:

I'm a bit confused about this listener. I'm setting new position (of course just once):

 mMapboxMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, zoom)); 

That works fine but the problem is with returned value, this is my basic code:

private void onCameraChangeListener(CameraPosition cameraPosition) {
        Timber.e("cameraPosition.zoom: " + cameraPosition.zoom + " mMapboxMap.getCameraPosition().zoom: " + mMapboxMap.getCameraPosition().zoom);
}

and here is the related log:

03-14 16:25:29.785 MapObserver: cameraPosition.zoom: 13.791596412658691 mMapboxMap.getCameraPosition().zoom: 13.791596412658691
03-14 16:25:29.801 MapObserver: cameraPosition.zoom: 14.0 mMapboxMap.getCameraPosition().zoom: 14.0
03-14 16:25:29.802 MapObserver: cameraPosition.zoom: 13.791596412658691 mMapboxMap.getCameraPosition().zoom: 14.0

The values coming from OnCameraChangeListener and getCameraPosition are slightly different.

@tobrun tobrun added bug Android Mapbox Maps SDK for Android labels Mar 15, 2016
@tobrun tobrun added this to the android-v4.0.0 milestone Mar 15, 2016
@mpuchala
Copy link

Hey,

I've got suggestion about this issue, maybe it would be helpful.

Please take a look at public final void animateCamera(CameraUpdate update, int durationMs, final MapboxMap.CancelableCallback callback) method in MapboxMap class - shouldn't you invalidate camera position onFinish()/onCancel() like you do it here?:

    public final CameraPosition getCameraPosition() {
        if (mInvalidCameraPosition) {
            invalidateCameraPosition();
        }
        return mCameraPosition;
    }

After quick test I get proper value in OnCameraChangeListener parameter when I have sth like that:

public MapboxMap.CancelableCallback mCameraAnimationCallback = new MapboxMap.CancelableCallback() {
        @Override
        public void onCancel() {
            onCameraAnimationFinished();
        }

        @Override
        public void onFinish() {
            onCameraAnimationFinished();
        }
    };

    private void onCameraAnimationFinished() {
        mIsCameraAnimation = false;
        Timber.e("[MapObserver] Camera Animation - finish");
        mMapboxMap.getCameraPosition();
    }

@tobrun
Copy link
Member Author

tobrun commented Mar 21, 2016

@mpuchala indeed invalidating the cameraposition in onCancel and onFinish produces better results.

@bleege
Copy link
Contributor

bleege commented Mar 21, 2016

Rebased and Merged into release-ios-3.2.0-android-4.0.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Android Mapbox Maps SDK for Android bug
Projects
None yet
Development

No branches or pull requests

3 participants