谷歌Android地图API V2:让我的轴承位置 [英] Android Google Maps API v2: get my bearing location

查看:155
本文介绍了谷歌Android地图API V2:让我的轴承位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想迫使相机行为像您使​​用的是导航,当你向左旋转90°意味着,相机做同样的事情。

I would like to force the camera to behave like you are using navigation, it means when you rotate 90° left, the camera does the same thing.

我有一个谷歌地图在我的位置(作为一个蓝色圆点)表示。

I have a Google Map where my location (as a blue dot) is shown.

mGoogleMap.setMyLocationEnabled(true);

当我移动时,蓝点是一个箭头,显示我的当前方位。我想获得这种轴承。

When I am moving, blue dot is with an arrow which shows my current bearing. I would like to get this bearing.

我使用得到我的当前位置的 FusedLocationApi 的:

I am getting my current location using FusedLocationApi:

 currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

code以下的动​​画镜头目前的位置,但是无影响。我可以添加轴承,但我不知道该值。

Code below is animating camera to current location, but without the bearing. I can add the bearing, but I don't know the value.

    @Override
    public void onLocationChanged(Location location) {

        LatLng latLng = new LatLng( location.getLatitude(), location.getLongitude() );
        mGoogleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
        mGoogleMap.animateCamera(CameraUpdateFactory.zoomTo(15));

    }

你知道如何获得当前位置的方向吗?我无法找到任何合适的信息。我将非常AP preciate任何帮助,您可以给我。

Do you know how to get the current location direction? I was unable to find any proper information about that. I would greatly appreciate any help you can give me.

感谢您

推荐答案

我想你可以尝试使用 getOrientation(R,定向)(和调整真北)以获取设备旋转。你可以参考<一个href="http://developer.android.com/reference/android/hardware/SensorManager.html#getOrientation(float[],%20float[])"相对=nofollow>这里。

I think you can try to use getOrientation(R, orientation) (and adjust for true north) to get the device rotation. You can refer to here.

此外,使用 CameraPosition 类的<​​a href =htt​​p://developer.android.com/reference/com/google/android/gms/maps/model /CameraPosition.html相对=nofollow>这里调节摄像头的位置。

Also, use the CameraPosition class here to adjust camera position.

编辑:我甚至找到了更好的解决方案。在使用 getBearing()方法地点类。

I even found better solution. Use getBearing() method in Location class.

if (location.hasBearing()) {
            CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(latLng)             // Sets the center of the map to current location
                .zoom(15)                   // Sets the zoom
                .bearing(location.getBearing()) // Sets the orientation of the camera to east
                .tilt(0)                   // Sets the tilt of the camera to 0 degrees
                .build();                   // Creates a CameraPosition from the builder
            mGoogleMap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
        }

这篇关于谷歌Android地图API V2:让我的轴承位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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