2

How I can enable the compass mode in Open Street Map?

Is there a method or do I need to create the orientation system by myself?

Michał Trybus
  • 11,526
  • 3
  • 30
  • 42
max246
  • 225
  • 3
  • 13

4 Answers4

2

This is how I enable the compass:

MapView oMap;
IMapController mapController;
.......

mapController = oMap.getController();
mapController.setZoom(zoom);
mapController.setCenter(new GeoPoint(latitude, longitude));
MyLocationNewOverlay oMapLocationOverlay = new 
MyLocationNewOverlay(getApplicationContext(),oMap);
oMap.getOverlays().add(oMapLocationOverlay);
oMapLocationOverlay.enableFollowLocation();
oMapLocationOverlay.enableMyLocation();   

CompassOverlay compassOverlay = new CompassOverlay(this, oMap);
compassOverlay.enableCompass();
oMap.getOverlays().add(compassOverlay);
sepehr
  • 803
  • 14
  • 28
Rocologo
  • 574
  • 5
  • 11
1

To show the compass on the map, use enableCompass() in MyLocationOverlay.

From MyLocationOverlay.java:

Enable orientation sensor (compass) updates and show a compass on the map. You will want to call enableCompass() probably from your Activity's Activity.onResume() method, to enable the features of this overlay. Remember to call the corresponding disableCompass() in your Activity's Activity.onPause() method to turn off updates when in the background.

If you want to rotate the map as well there's a branch of osmdroid implementing that functionality: http://code.google.com/p/osmdroid/source/browse/branches/rotation/OpenStreetMapViewer/src/org/osmdroid/MapActivity.java?r=914

Kleist
  • 7,785
  • 1
  • 26
  • 30
  • Yes that is useful but I need to rotate the map as well – max246 Nov 22 '11 at 12:20
  • 1
    Then you should update your question, or ask a new one. As far as i can tell, this is not supported in osmdroid. – Kleist Nov 22 '11 at 13:21
  • 1
    Yes I found the solution : http://code.google.com/p/osmdroid/source/browse/branches/rotation/OpenStreetMapViewer/src/org/osmdroid/MapActivity.java?r=914 – max246 Nov 22 '11 at 18:55
  • 1
    In trunk, MyLocationOverlay says it is deprecated by MyLocationNewOverlay, but MyLocationNewOverlay does not have an enableCompass() function. Is there a new way to draw the compass? – David Doria Aug 27 '13 at 16:51
  • Old question and answer, but osmdroid does do map rotation – spy Dec 19 '15 at 12:57
0

Since the question isn't clear, I'll give you what I "think" you're asking for, which is a compass on the screen.

CompassOverlay mCompassOverlay = new CompassOverlay(getContext(),
            new InternalCompassOrientationProvider(getContext()),
            mMapView);
mCompassOverlay.enableCompass();
mMapView.getOverlays().add(this.mCompassOverlay);
arne.z
  • 3,242
  • 3
  • 24
  • 46
spy
  • 3,199
  • 1
  • 18
  • 26
0

You just need to pass context and mapview instance

CompassOverlay compassOverlay = new CompassOverlay(this, map);
compassOverlay.enableCompass();
map.getOverlays().add(compassOverlay);

create compass overlay, enable and then add it to the map overlays to show