문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top