max246
max246

Reputation: 225

Enable Compass OSMDROID

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?

Upvotes: 2

Views: 6394

Answers (4)

Towsif Ahamed Labib
Towsif Ahamed Labib

Reputation: 686

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

Upvotes: 0

Rocologo
Rocologo

Reputation: 604

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);

Upvotes: 2

spy
spy

Reputation: 3258

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);

Upvotes: 0

Kleist
Kleist

Reputation: 7985

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

Upvotes: 1

Related Questions