Android地图V2旋转的MapView带指南针 [英] Android Maps v2 rotate mapView with compass

查看:374
本文介绍了Android地图V2旋转的MapView带指南针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即时通讯开发一个应用程序,它需要旋转带指南针的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.

这篇关于Android地图V2旋转的MapView带指南针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆