Android Maps v2 使用指南针旋转 mapView [英] Android Maps v2 rotate mapView with compass

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

问题描述

我正在开发一个需要使用指南针旋转 mapView 的应用程序.我知道如何旋转相机,但我需要用罗盘旋转 mapView.中心点应该是当前位置.我找到了 Maps V1 的代码,但我需要用 Maps V2 来做

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

推荐答案

好的,我自己想出来了.首先,您需要从罗盘计算方位.然后可以旋转 Maps 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));

    }

在您的代码中设置 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 Maps v2 使用指南针旋转 mapView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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