谷歌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 came...

我想迫使相机行为像您使​​用的是导航,当你向左旋转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,定向)(和调整真北)以获取设备旋转。你可以参考这里。

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 类的这里调节摄像头的位置。

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));
        }
阅读全文

相关推荐

最新文章