I'm currently developing an app using OSMdroid 5.1 on a Samsung Galaxy Tab E. My problem here is I can't get the compass to show up at all. I searched hours on the internet and in OSMdroid source code but I couldn't figure it out. I decided to test it on my personal phone (Samsung Galaxy S4) and turns out it appears and work perfectly on this device.
Tablet is running on Android 5.1.1
Phone is running on Android 5.0.1
I am using Android Studio 2.1
The following is all the code that refers to CompassOverlay.
@Override
public void onResume() {
super.onResume();
compassOverlay.enableCompass();
myLocationOverlay.enableMyLocation();
//mMyLocationOverlay.enableFollowLocation();
}
@Override
public void onPause() {
super.onPause();
compassOverlay.disableCompass();
this.myLocationOverlay.disableMyLocation();
//this.myLocationOverlay.disableFollowLocation();
}
private void mapEndConfig() {
this.osmv.setBuiltInZoomControls(true);
this.osmv.setMultiTouchControls(true);
osmv.getController().setZoom(11);
double lon = -64.5996; //-74.15702819824206; //,45.6294
double lat = 45.6294; //40.64938745451832;
IGeoPoint point = new GeoPoint(lat, lon); // lat lon and not inverse
osmv.getController().setCenter(point);
myLocationOverlay = new MyLocationNewOverlay(this, osmv);
compassOverlay = new CompassOverlay(this, new InternalCompassOrientationProvider(this), this.osmv, mResourceProxy);
osmv.getOverlayManager().add(myLocationOverlay);
osmv.getOverlayManager().add(compassOverlay);
/*anotherOverlayItemArray = new ArrayList<OverlayItem>();
anotherOverlayItemArray.add(new CompassOverlay());
ItemizedIconOverlay<OverlayItem> anotherItemizedIconOverlay
= new ItemizedIconOverlay<OverlayItem>(
this, anotherOverlayItemArray, null);
this.mOsmv.getOverlays().add(anotherItemizedIconOverlay);*/
/*myLocationOverlay.runOnFirstFix(new Runnable() {
public void run() {
osmv.getController().animateTo(myLocationOverlay.getMyLocation());
}
});*/
}
Nobody seems to have encountered something like that with the compass before, does anyone have a solution?
Okay I found the problem. It's because the Samsung Galaxy Tab E does not have a magnetometer for the compass.
When OSMdroid does not detect it, instead of giving an error or warning, it simply does not show it.