Jul 3, 2012

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.


3 comments:

  1. i have fully write this code in eclipse and i want to display it on my emulator but its only shows a grid pattern with scale on the upper right corner but not showing a map can any body tell how the map can be shown in it.

    ReplyDelete
    Replies
    1. because map is always stored in SD card ..its not like google maps where it is cached inside phone internal memory...run it on mobile directly from eclipse or android studio and disconnect the data cable after that wait for some time to let the device prepare the SD card and it will display man .... :)

      Delete
  2. the mylocation does not appear . is there any problem ? the location is set to my current location but the icon does not appear.

    please do suggest a solution.

    thank you

    ReplyDelete

Infolinks In Text Ads