Reputation: 692
I want to integrate OSM into my application to show the map of a given location. I want to show the north direction on the map, even when the user rotates the map. The OsmAnd app has a compass mode exactly like this, but the osmdroid API does not seem to have it.
Relevant code
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();
}
}
Is there any built in solution I miss, or I have to implement something on my own?
Upvotes: 0
Views: 188
Reputation: 3450
Usage of CompassOverlay is shown in the sample app OpenStreetMapViewer:
Upvotes: 0