Android Google Maps API v2:获取我的方位

姆雷克

我想强制相机像使用导航时那样工作,这意味着当您向左旋转90°时,相机会执行相同的操作。

我有一个Google地图,其中显示了我的位置(以蓝色圆点表示)。

mGoogleMap.setMyLocationEnabled(true);

当我移动时,带有箭头的蓝点表示我当前的方位。我想了解一下。

我正在使用FusedLocationApi获取当前位置

 currentLocation = LocationServices.FusedLocationApi.getLastLocation(mGoogleApiClient);

下面的代码是使摄像机动画到当前位置,没有方位角。我可以添加轴承,但我不知道其价值。

    @Override
    public void onLocationChanged(Location location) {

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

    }

您知道如何获取当前的位置方向吗?我找不到有关此的任何适当信息。我将不胜感激,您可以给我任何帮助。

谢谢

bjiang

我认为您可以尝试使用getOrientation(R, orientation)(并调整为真北)get the device rotation你可以参考这里

另外,请在此处使用CameraPosition该类来调整相机位置。

编辑:我什至找到了更好的解决方案。使用Location类中的getBearing()方法

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));
        }

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章