Question

I am getting google directions and displaying them on a V2 Mapview. So the resulting map displayed a start point, end point, and the route between them. I add them to the map as follows:

LatLngBounds bounds = builder.build();
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding);
mapView.animateCamera(cu);

I would now like the map rotated so that the start and end point are on the same horizontal plane. The map displays a different route each time, so I need logic to calculate how many degrees the rotation needs to be, and code to actually rotate the map, within the specified bounds as in the code above. I'm struggling to find a way of doing this.

Was it helpful?

Solution

try this, i implemented that some time ago. (If u dont want to have the Tilt effect) - just set it to Zero)

targetBearing = destinationLocation.bearingTo(myCurrentLocation);
    CameraPosition cameraPosition = new CameraPosition.Builder()
            .target(new LatLng(latitudeCurrentLocation,
                    longitudeCurrentLocation)).bearing(targetBearing + 530)
            .tilt(67).zoom(15).build();

    map.animateCamera(
            CameraUpdateFactory.newCameraPosition(cameraPosition), 5000,
            null);

EDIT: bearing(targetBearing + 530) this does the rotation in degrees.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top