Reputation: 627
First let me state that this question concerns Map v2 API for my native Android application. Second, I've looked at a number of stackOverflow postings on how to detect panning changes on Map v2 API (e.g., How to handle onTouch event for map in Google Map API v2?) but at this point it seems like these solutions are bit of overkill given my requirements.
Here is what I'm trying to accomplish...
Detect if the user has changed the original camera position (zoom or pan) of a map and if so display a reset button on the map so that the user can simply reset the map to the original position by tapping the reset button.
Here is my approach.....
To accomplish this I use the "OnCameraChangeListener getCameraChangeListener()" callback and on callback test whether the camera position passed in (via the onCameraChange(CameraPosition position) is different than the "original" camera position of the rendered map. If it is different then I display the reset button so that the user can return the map to it's position.
Here is the problem that I'm encountering....
Everything works as expected except that when the "OnCameraChange" callback is called in response to resetting the map image to it's "original" position (via the "reset" button) the camera "position" passed in via the "onCameraChange" callback doesn't match the "original" map position (as I would have expected) even though the map has been reset appropriately.
This creates a problem for me because if the Camera position passed in via the callback doesn't match the "original" position then I make the reset button visible. But in this because I have successfully reset the map to it's original position I no longer want the reset button to be visible...hence my problem.
Here is where I need your help....
Regards.
Upvotes: 0
Views: 897
Reputation: 21
Looks like the precision is lost because GMaps is casting LatLng values from Double to float somewhere before passing to onCameraChange
This works in my case:
public boolean equals(LatLng original, LatLng target) {
return ((float) original.latitude == (float) target.latitude
|| (float) original.longitude == (float) target.longitude);
}
Upvotes: 0
Reputation: 22232
I have just tested that and also reported on gmaps-api-issues.
For now you will have to write your own equals(CameraPosition, CameraPosition)
, which take into accont target LatLng
is different by a very small value.
My test shows this:
CameraPosition{target=lat/lng: (0.2345,12.98231), zoom=5.4231, tilt=13.33, bearing=40.0}
CameraPosition{target=lat/lng: (0.23449985034422136,12.982310056686401), zoom=5.4231, tilt=13.33, bearing=40.0}
Upvotes: 1