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

Commit

Permalink
[android] #3244 - Adding initial camera position in CameraActivity. B…
Browse files Browse the repository at this point in the history
…uilding MapView's getCameraPosition() and animateCamera().
  • Loading branch information
bleege committed Dec 11, 2015
1 parent ae8e7a7 commit 3ef877d
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
import com.mapbox.mapboxsdk.annotations.PolylineOptions;
import com.mapbox.mapboxsdk.annotations.Sprite;
import com.mapbox.mapboxsdk.annotations.SpriteFactory;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdate;
import com.mapbox.mapboxsdk.constants.MyBearingTracking;
import com.mapbox.mapboxsdk.constants.MyLocationTracking;
Expand Down Expand Up @@ -1429,6 +1430,15 @@ public void setTiltEnabled(boolean tiltEnabled) {
// Camera API
//

/**
* Gets the current position of the camera.
* The CameraPosition returned is a snapshot of the current position, and will not automatically update when the camera moves.
* @return The current position of the Camera.
*/
public final CameraPosition getCameraPosition () {
return new CameraPosition(getCenterCoordinate(), (float)getZoomLevel(), (float)getTilt(), (float)getBearing());
}

/**
* Animates the movement of the camera from the current position to the position defined in the update.
* During the animation, a call to getCameraPosition() returns an intermediate location of the camera.
Expand All @@ -1438,6 +1448,11 @@ public void setTiltEnabled(boolean tiltEnabled) {
*/
public final void animateCamera (CameraUpdate update) {

setBearing(update.getBearing());
setTilt(new Double(update.getTilt()), 0L);
setCenterCoordinate(update.getTarget());
setZoomLevel(update.getZoom());

}


Expand Down Expand Up @@ -2459,6 +2474,10 @@ void update() {
}
}

double getBearing() {
return mNativeMapView.getBearing();
}

// Used by UserLocationView
void setBearing(float bearing) {
mNativeMapView.setBearing(bearing, 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import com.mapbox.mapboxsdk.camera.CameraPosition;
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
import com.mapbox.mapboxsdk.constants.Style;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.utils.ApiAccess;
import com.mapbox.mapboxsdk.views.MapView;

Expand Down Expand Up @@ -42,6 +45,15 @@ protected void onStart() {
public void onResume() {
super.onResume();
mMapView.onResume();


CameraPosition cameraPosition = new CameraPosition.Builder()
.target(new LatLng(44.50128, -88.06216)) // Sets the center of the map to Mountain View
.zoom(17) // Sets the zoom
.bearing(90) // Sets the orientation of the camera to east
.tilt(30) // Sets the tilt of the camera to 30 degrees
.build(); // Creates a CameraPosition from the builder
mMapView.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}

@Override
Expand Down

0 comments on commit 3ef877d

Please sign in to comment.