Android 谷歌地图 API v2 : get my bearing location

标签 android google-maps google-maps-android-api-2

我想强制相机的行为就像您正在使用导航一样,这意味着当您向左旋转 90° 时,相机会做同样的事情。

我有一个 Google map ,其中显示了我的位置(作为蓝点)。

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

    }

你知道如何获取当前位置方向吗?我找不到任何关于那个的适当信息。如果您能给我任何帮助,我将不胜感激。

谢谢

最佳答案

我认为您可以尝试使用 getOrientation(R, orientation)(并针对真北进行调整)获取设备旋转。可以引用here .

此外,使用 CameraPositionhere调整相机位置。

编辑:我什至找到了更好的解决方案。在 Location 中使用 getBearing() 方法类(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 : get my bearing location,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28951974/

相关文章:

android - Google maps API V2 安装到真机后黑屏

ios - Google Map SDK 使用标记时使用的内存量不合理

android - 支持 MapFragment 而不是 MapFragment

java - 如何在 Android 10 (Android Q) 中访问外部存储?

android - 如何取消注册传感器监听器?

javascript - Google Places Autocomplete 限制在附近

android - Google map for android 我的位置自定义按钮

android - 使用 Google API(Lv. 17)在真正的 Android 2.3 设备上空白 GoogleMap

android - 在eclipse中运行而不调试

java - Android 蓝牙发现 API 无法在 Android 6.0 上运行