奥斯姆德罗德:按照地图向北旋转



我想将OSM集成到我的应用程序中,以显示给定位置的地图。我想在地图上显示北向,即使用户旋转地图也是如此。OsmAnd应用程序有一个类似的指南针模式,但osmroid API似乎没有

相关代码

public class MapFragment extends Fragment {
FragmentMapBinding binding;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
binding = FragmentMapBinding.inflate(inflater);
Configuration.getInstance().load(getContext(), PreferenceManager.getDefaultSharedPreferences(getContext()));
binding.map.setTileSource(TileSourceFactory.MAPNIK);
binding.map.setMultiTouchControls(true);
CompassOverlay compassOverlay = new CompassOverlay(getContext(), new InternalCompassOrientationProvider(getContext()), binding.map);
compassOverlay.enableCompass();
binding.map.getOverlays().add(compassOverlay);
RotationGestureOverlay rotationOverlay = new RotationGestureOverlay(binding.map);
rotationOverlay.setEnabled(true);
binding.map.getOverlays().add(rotationOverlay);
return binding.getRoot();
}
@Override
public void onResume() {
super.onResume();
binding.map.onResume();
}
@Override
public void onPause() {
super.onPause();
binding.map.onPause();
}
}

有没有我错过的内置解决方案,或者我必须自己实现一些东西?

CompassOverlay的用法显示在示例应用程序OpenStreetMapViewer:中

https://github.com/osmdroid/osmdroid/blob/master/OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/location/CompassRoseSample.java

最新更新