I'm using the code of MapsDemo Sample to draw a Map that rotates according to the compass, but enableCompass is not working to show the compass on MapView. I tried to add this compass http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Compass.html. But when I add it to my application, the arrow appears frozen. Any ideas?
Asked
Active
Viewed 2,147 times
0
-
Solution is here: https://stackoverflow.com/a/74740478/851699 – Peter Dec 09 '22 at 08:23
1 Answers
0
Bear in mind that it will only work on actual hardware.
Put this line in onCreate
:
MyLocationOverlay me = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(me);
Then add this:
@Override
protected void onResume() {
super.onResume();
me.enableCompass();
}
@Override
public void onPause() {
super.onPause();
me.disableCompass();
}
Here is a sample project that enables the compass on MyLocationOverlay
that definitely works, though you will need to substitute in your own android:apiKey
value.

Faizal
- 783
- 1
- 6
- 23