Display Compass on osmdroid MapView

To display compass on osmdroid MapView, simple call enableCompass() in onResume() and call disableCompass() in onPause().

Display Compass on osmdroid MapView


Modify from last article "osmdroid MapView - to follow user location".

 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  myLocationOverlay.enableMyLocation();
  myLocationOverlay.enableCompass();
  myLocationOverlay.enableFollowLocation();
 } 

 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  myLocationOverlay.disableMyLocation();
  myLocationOverlay.disableCompass();
  myLocationOverlay.disableFollowLocation();
 }


It work as expected in Android 3 device, but fail in Android 4! The simplest solution is to specify target SDK version to API Level 11 in AndroidManifest.xml.

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="11" />


Next:
- osmdroid MapView: set zoom level and add scale bar.


0 Response to "Display Compass on osmdroid MapView"

Posting Komentar