Android地图V2旋转的MapView带指南针指南针、地图、Android、MapView

2023-09-05 00:07:32 作者:都是酸牛奶装什么特仑苏啊

即时通讯开发一个应用程序,它需要旋转带指南针的MapView。我知道如何旋转摄像头,但我需要旋转带指南针的MapView。中心点应的当前位置。我发现codeS的地图V1,但我需要用地图V2

Im developing an app which needs to rotate the mapView with compass. i know how to rotate the camera but i need to rotate the mapView with compass. the center point should be the current location. i found codes for Maps V1 but i need to do it with Maps V2

推荐答案

OK,我理解了它自己。首先你需要计算轴承的罗盘。 那么地图API-2摄像头可以旋转。

OK, i figured it out myself. first you need to calculate the bearing from the compass. then the Maps api-2 camera can be rotated.

public void updateCamera(float bearing) {
            CameraPosition currentPlace = new CameraPosition.Builder()
                    .target(new LatLng(centerLatitude, centerLongitude))
                    .bearing(bearing).tilt(65.5f).zoom(18f).build();
            googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(currentPlace));

    }

在你的code组 SensorListener 键,调用此方法在 onSensorChanged 事件。我添加了一个倾斜值,这样的地图会以3D旋转。

set SensorListener in your code and call this method in onSensorChanged event. i have added a tilt value so the map will rotate in 3D.

 
精彩推荐
图片推荐