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

OnCameraChangeListener vs getCameraPosition #4326

Closed

Description

@tobrun

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.

Activity

  1. added
    Android
    on Mar 15, 2016
  2. added this to the android-v4.0.0 milestone on Mar 15, 2016
  3. mpuchala commented on Mar 16, 2016

    @mpuchala

    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();
        }
    
  4. tobrun commented on Mar 21, 2016

    @tobrun
    MemberAuthor

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

  5. added a commit that references this issue on Mar 21, 2016
  6. self-assigned this
    on Mar 21, 2016
  7. added a commit that references this issue on Mar 21, 2016
  8. added 2 commits that reference this issue on Mar 21, 2016
  9. bleege commented on Mar 21, 2016

    @bleege
    Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Androidbug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions