android - 根据手机当前方向旋转 Mapbox map

标签 android android-mapview mapbox

我正在尝试旋转 map ,使其始终面向我们使用 MapBox Android 前进的方向。目前,这是我尝试但没有成功的方法:

这是我初始化 mapbox map 的地方:

mapView.getMapAsync(mapboxMap -> {
    Log.d(TAG, "Map is initialized");
    map = mapboxMap;
    map.getTrackingSettings().setMyBearingTrackingMode(MyBearingTracking.COMPASS);
});

这是我启用位置的地方;

private void enableLocation(boolean enabled) {
    map.setMyLocationEnabled(enabled);
    if (enabled) {
        locationServices.addLocationListener(location -> {
            if (location != null) {
                // Move the map camera to where the user location is

                if (location.getBearing() != 0) {
                    map.setCameraPosition(new CameraPosition.Builder()
                            .target(new LatLng(location))
                            .bearing(location.getBearing())
                            .build());
                } else {
                    map.setCameraPosition(new CameraPosition.Builder()
                            .target(new LatLng(location))
                            .build());
                }
                Log.e(TAG, "location bearing:" + location.getBearing());
            }
        });
    }
}

我最终在最新版本的 MapBox 上使用了它:

mapView.getMapAsync(mapboxMap -> {
    Log.d(TAG, "Map is initialized");
    map = mapboxMap;
    map.getTrackingSettings().setMyBearingTrackingMode(MyBearingTracking.TRACKING_FOLLOW);
});

最佳答案

您使用的是哪个版本的 SDK?我 merged a compass listener fix上个月修复了罗盘方位跟踪。您可以阅读有关 issue here 的更多信息.尝试更新到 4.2.0-beta.3 并使用您在问题中发布的第一个 fragment 。让我知道这是否是您正在寻找的修复方法!

关于android - 根据手机当前方向旋转 Mapbox map ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39666340/

相关文章:

reactjs - Deck.GL 与 CARTO 和 React

android - 什么是 NoSaveStateFrameLayout?

java - 清除 Android 3.x 上的图案锁定

android - MapView保持上下文导致内存泄漏

android - RecyclerView 中的谷歌地图 View

android - 如何将 mapbox 语言更改为波斯语/波斯语

mapbox - Mapbox Tilequery API 的高程错误

javascript - 样式化 React Native Picker

android - ActionBarSherlock ShareActionProvider 问题

android - 如何在 mapview 上固定项目的 onTap 区域?