Can I use 2 cameraUpdates with one animateCamera? - android

I am trying to zoom on a map
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(mBounds, this.getResources().getDisplayMetrics().widthPixels,
height, padding);
mMap.animateCamera(cameraUpdate, duration, null);
And after that I want to scroll the map vertically
CameraUpdate cameraUpdate =
CameraUpdateFactory.scrollBy(0, amountToScroll);
mMap.animateCamera(cameraUpdate, duration, null);
The thing is ... it is not working. If I call the scroll right after the zoom, only the scroll is taken into account. If I scroll the map once the zoom animation is finished I will have 2 animations.
I would like to do both operations with the same animation, is it possible?

If you call animateCamera multiple times, only the last one will finish its action.
The easy fix would be to use moveCamera instead of the first call to animateCamera, but that's not a nice solution from UX perspective.
The other way would be to do the math yourself and fill mBounds with the bounds you really want to show.

The easiest way to do it is to use CancelableCallback. You should check the first action is complete and then call the second:
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, size.x, height, 0), new CancelableCallback() {
#Override
public void onFinish() {
CameraUpdate cu_scroll = CameraUpdateFactory.scrollBy(0, 500);
mMap.animateCamera(cu_scroll);
}
#Override
public void onCancel() {
}
});

Related

Facebook fresco library: ZoomableDraweeView check image is zoomed or in original state

I am using ZoomableDraweeView from arlindiDev/FrescoDoubleTapZoom in my app it is working perfectly for pinch and double tap zoom effect but problem is that I want a zoom checking listener in my Mainactivity.class that check whether image is zoom state or in original state.
ChechZoom.java
interface public interface CheckZoom {
void isZoomed(Boolean zoom);
}
implemented in mainactivity.java to observe zoom state
and called in AnimatedZoomableController.java 's method
public void zoom(PointF viewPoint) {
PointF imagePoint = mapViewToImage(viewPoint);
if(getScaleFactor() < getMaxScaleFactor()) {
**checkZoom.isZoomed(true);**
zoomToPoint(getMaxScaleFactor(), imagePoint, viewPoint, LIMIT_ALL, 400, null);
} else {
**checkZoom.isZoomed(false);**
zoomToPoint(getMinScaleFactor(), imagePoint, viewPoint, LIMIT_ALL, 400, null);
}
}
it work fine for double tap zoom effect notify image is zoomed or not in main activity.
but problem is where should i put this line of code checkZoom.isZoomed(true or false); to detect pinch zoom effect.

Google map LatLngBounds offset

I have this code
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.include(mainLocation);
builder.include(userLocation);
LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 0);
mMap.animateCamera(cu);
And this works it shows bounds but i would like to show bounds on the top half of the screen (is there a way to put offset y?).
(Hope this picture will explain things better)
If I understand you correctly, what you get now is that map is centered, meaning your provided locations are centered on the map. And you want those locations to be on the upper part of the screen.
It seems there is not such an API, that would allow to apply padding to bottom only.
You can add a fake location to LatLngBounds.Builder at the lower part of the screen, now the CameraUpdate would include that point also, which will shift your 2 real points on the upper part.
You can use the setPadding method from the GoogleMap object.
In your case you will need to add a bottom padding:
mMap.setPadding(0, 0, 0, 150);
Maybe late, but i solved this. I make bottom padding for map, before call animateCamera, and return padding after update.
val heightValue = (Resources.getSystem().displayMetrics.heightPixels * 0.5).toInt()
map.setPadding(0,0,0,heightValue)
val update = CameraUpdateFactory.newLatLngBounds(bounds,50)
map.animateCamera(update,object:GoogleMap.CancelableCallback{
override fun onFinish() {
inUi {
map.setPadding(0,0,0,0)
}
}
override fun onCancel() {}
})
Here is the best solution I found to achieve this effect.
You force the padding you need before animating the camera, and immediately after, you reset the padding to whatever ever value.
map.setPadding(left, top, right, bottom) // In your example, this will be the only non-zero value.
animateCamera(cameraUpdate) // Trigger the animation
map.setPadding(0, 0, 0, 0) // Reset the padding

Set both bounds and tilt in google maps v2

I need to set at the same time tilt and bounds to th camera in my map.
So I think I need this:
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50));
but I don't know how can I add also tilt.
If I try to insert other code, like this:
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder()
.target(mMap.getCameraPosition().target)
.zoom(mMap.getCameraPosition().zoom)
.bearing(30)
.tilt(45)
.build()));
only the second animation is done. So, the tilt is applied, but I have not the correct bounds.
So, the question, as said in the question's title: how can I set both tilt and bounds for my camera?
Why don't you wait for the first animation with the bounds to complete, then animate the tilt when it finishes?
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 50),
new CancelableCallback() {
#Override
public void onFinish() {
mMap.animateCamera(CameraUpdateFactory.newCameraPosition(new CameraPosition.Builder(mMap.getCameraPosition())
.bearing(30)
.tilt(45)
.build()));
}
#Override
public void onCancel() {
}
});

Moving UI Controls of GoogleMap, while not moving the visible region

I want to move the mylocation-Button of an GoogleMap in android from the top-right to the bottom-right corner of the display.
The android APIs offer this function to do this.
GoogleMap.setPadding(int left, int top, int right, int bottom)
My problem is that
getCameraPosition() will return the center of the padded region.
Projection.getVisibleRegion() will return the padded region.
So after the user touches the "myLocation"-Button, the users location is not in the center of the map anymore.
What is the best way to move the UI-Controls, but leave the visible Region unpadded?
Any help is appreciated!
GoogleMap.set padding() seems to only make sense if want for example split your screen so that the map only covers a part of it.
So what I did so solve this is create my own my-location button that responds to a click like this:
Layout.xml
<Button
android:id="#+id/myLocation"
android:layout_width="48dp"
android:layout_height="48dp"
android:background="#drawable/button_my_position" />
implementing onLocationChanged() so that I always have access to my current location
#Override
public void onLocationChanged(Location location) {
this.currentLocation = location;
}
my-location clickListener:
myPosition = (Button)getView().findViewById(R.id.myLocation);
myPosition.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
map.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(currentLocation
.getLatitude(), currentLocation.getLongitude())));
}
});

How to adjust zoom level to fit boundary and then center map in marker offset?

I have a google map (com.google.android.gms.maps.GoogleMap) where I have some markers set.
I am able to, separately,
1) adjust zoom level and center the map on a boundary:
mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10));
and
2) center the map above one of the markers:
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude
+ offset, markerSelected.getPosition().longitude);
mMap.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
but, for the life of me, I can't just do both, adjust the zoom level using newLatLngBounds and then center the map somewhere else. Whatever I do last is what I see happening in the map.
How do I do this?
For future visitors this is how you can chain camera animations:
map.animateCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10), 2000, new CancelableCallback() {
#Override
public void onFinish() {
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude + offset, markerSelected.getPosition().longitude);
map.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
}
#Override
public void onCancel() {
}
});
Also see AnimateCameraChainingExampleActivity.java for an example how to chain infinitely.
Try using both moveCamera and animateCamera...
mMap.moveCamera(CameraUpdateFactory.newLatLngBounds(getZoomBounds(), 10));
LatLng poiSelectedLatLng = new LatLng(markerSelected.getPosition().latitude
+ offset, markerSelected.getPosition().longitude);
mMap.animateCamera(CameraUpdateFactory.newLatLng(poiSelectedLatLng));
moveCamera will move directly to that spot while animateCamera will provide the moving effect. They are linear in nature so one will happen after the other however layering them as I have done above will provide the potential effect you are looking for.
If you are trying to see the actual movement of both calls on the UI you will need to register for the callback post the completion of the animation as needed.

Categories

Resources