GoogleMap moveCamera or animateCamera according to LatLngBounds is not exact

I have some doubts about the accuracy of moveCamera and animateCamera with CameraUpdateFactory.newLatLngBounds (). Im maps the LatLngBounds im object that creates and dispatches moveCamera / animateCamera (CameraUpdateFactory.newLatLngBounds ()), to map.getProjection () as a parameter. GetVisibleRegion (). LatLngBounds in the onCameraChange () event or even GoogleMap.CancelableCallback # onFinish (), They do not match . Has anyone encountered this issue? This is mistake?

My code is:

final LatLngBounds boundingBox = MapUtils.getBoundingBox(mCurrLocation.getLatitude(), mCurrLocation.getLongitude(), mCurrRadius); try { if (animate) { map.animateCamera(CameraUpdateFactory.newLatLngBounds(boundingBox, 0), new GoogleMap.CancelableCallback() { @Override public void onFinish() { if (!boundingBox.equals(map.getProjection().getVisibleRegion().latLngBounds)) { map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundingBox, 0)); } } @Override public void onCancel() { } }); } else { map.moveCamera(CameraUpdateFactory.newLatLngBounds(boundingBox, 0)); } } 

Please ignore the way the two objects are compared here (equals). I also debugged the code and checked 2 objects and saw that they did not match -

moveCamera:

boundingBox -

LatLngBounds {southwest = lat / lng: (32.08455383290544.34.773394063736845), northeast = lat / lng: (32.09730731777191,34.788375176773286)}

map.getProjection (). getVisibleRegion (). latLngBounds -

LatLngBounds {southwest = lat / lng: (32.084496299473756.34.77339383214712), northeast = lat / lng: (32.09736452396455,34.78837497532368)}

animateCamera:

boundingBox -

LatLngBounds {southwest = lat / lng: (40.70798493778415, -74.01434069136418), northeast = lat / lng: (40.72072004852845, -73.99760391411343)}

map.getProjection (). getVisibleRegion (). latLngBounds -

LatLngBounds {southwest = lat / lng: (40.70798500292429, -74.01539381593466), northeast = lat / lng: (40.72071968970514, -73.99655096232891)}

+4
source share
2 answers

It looks like a combination like bug && !bug .

For a description of the error, see this: http://code.google.com/p/gmaps-api-issues/issues/detail?id=5353

Basically you will have differences at the 5th or 6th decimal places.

Another problem is that when you send LatLngBounds to one of these functions, the resulting LatLngBounds will be new, which exactly matches the screen, and your original will be inside it.

0
source

There is an error with animateCamera and LatLngBounds. The method does not move the camera exactly to the expected area. How do I know that? I confirmed that by adding the following code:

 private LatLngBounds mBoundingBox; private boolean mCameraAnimated; public void setCurrentLocation(Location currentLocation, String radius, boolean animate) { mCurrLocation = currentLocation; mCurrRadius = MapUtils.getRadiusDecimalValue(radius); mBoundingBox = MapUtils.getBoundingBox(mCurrLocation.getLatitude(), mCurrLocation.getLongitude(), mCurrRadius); mCameraAnimated = animate; if (animate) { mEventMap.animateCamera(CameraUpdateFactory.newLatLngBounds(mBoundingBox, 0)); } else { mEventMap.moveCamera(CameraUpdateFactory.newLatLngBounds(mBoundingBox, 0)); } } @Override public void onCameraChange(CameraPosition cameraPosition) { // This ugly solution was added because there is a bug with camera animate which doesn't move to the correct bounding box. if (mBoundingBox != null && !mBoundingBox.equals(mEventMap.getProjection().getVisibleRegion().latLngBounds)) { LatLngBounds originalBoundingBox = mBoundingBox; mBoundingBox = null; if (mCameraAnimated) { mCameraAnimated = false; mEventMap.moveCamera(CameraUpdateFactory.newLatLngBounds(originalBoundingBox, 0)); return; } } ... 

Now, after an extra moveCamera, the camera is positioning correctly.
The new problem is that onCameraChange sometimes fails to run this extra moveCamera, and therefore im doesn't execute my actual onCameraChange code (marked as "...").

0
source

Source: https://habr.com/ru/post/1493937/


All Articles