Android – Google Maps V2 centers and rotates the camera position to accommodate the two markers

I'm trying to use the camera to move to fit my two tags and keep them at the same level. Therefore, this means modifying the zoom to fit them and turning the camera to fit the tags on the same line

The next two photos will clarify my question:

So what I have done so far is:

public void centerIncidentRouteOnMap(List<LatLng> copiedPoints) {
        double minLat = Integer.MAX_VALUE;
        double maxLat = Integer.MIN_VALUE;
        double minLon = Integer.MAX_VALUE;
        double maxLon = Integer.MIN_VALUE;
        for (LatLng point : copiedPoints) {
            maxLat = Math.max(point.latitude, maxLat);
            minLat = Math.min(point.latitude, minLat);
            maxLon = Math.max(point.longitude, maxLon);
            minLon = Math.min(point.longitude, minLon);
        }
        final LatLngBounds bounds = new LatLngBounds.Builder().include(new LatLng(maxLat, maxLon)).include(new LatLng(minLat, minLon)).build();
        mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 120));
}

But this will only fit the two markers on the screen, so I need to know how to rotate the camera at the right angle to get the last picture

Who can help me with this?

thank you!

resolvent:

In pseudo code, try something similar:

CameraPosition cameraPosition = new CameraPosition.Builder()
.target(Your_target)      // Sets the center of the map
.zoom(YourZoom)                   // Sets the zoom
.bearing(Your_Angle)                // -90 = west, 90 = east
.tilt(Some_Tilt)      

map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));

To retrieve angles:

float xDiff = x2 - x1;
float yDiff = y2 - y1;
return Math.atan2(yDiff, xDiff) * 180.0 / Math.PI;

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>