Android Google Maps API v2: get my bearing location

I would like to make the camera behave as if you are using navigation, which means that when you rotate 90 ° to the left, the camera does the same.

I have a Google map showing my location (like a blue dot).

mGoogleMap.setMyLocationEnabled(true);

When I move, a blue dot with an arrow that shows my current bearing. I would like to get this bearing.

I get my current location using FusedLocationApi:

 currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

Below is the animation code for the camera at its current location , but without a bearing. I can add a bearing, but I do not know the value.

    @Override
    public void onLocationChanged(Location location) {

        LatLng latLng = new LatLng( location.getLatitude(), location.getLongitude() );
        mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(15));

    }

, ? . , .

+4
1

, getOrientation(R, orientation) ( ) get the device rotation. .

, CameraPosition .

EDIT: . getBearing() Location.

if (location.hasBearing()) {
            CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(latLng)             // Sets the center of the map to current location
                .zoom(15)                   // Sets the zoom
                .bearing(location.getBearing()) // Sets the orientation of the camera to east
                .tilt(0)                   // Sets the tilt of the camera to 0 degrees
                .build();                   // Creates a CameraPosition from the builder
            mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
        }
+4

All Articles