Question

I have a MapView with an ImageView with an arrow that points towards a specific location. I´m doing the pointing by rotating the ImageView, by calculating the bearing (orientation) of the compass by means of getOrientation() - the heading with geoField.getDeclination() and bearing with myLocation.bearingTo(finalDestiny).

The algorithm works perfectly, I get the arrow pointing exactly where I want to. The only problem is that to be able to getOrientation() it is needed to enableCompass(), otherwise it returns NaN. At the same time, enableCompass() draws the default google compass on the MapView, which I don't want to display.

How can I do so? it is possible to calculate this bearing "manually" using the sensors so I don't need to use enableCompass()?

Was it helpful?

Solution

You should implement a class extends MyLocationOverlay and override drawCompass() without any code, I just try it and work perfectly. In your activity, enableCompass() will not draw compass.

public class CustomMyLocation extends MyLocationOverlay {
//...


    @Override
    protected void drawCompass(Canvas canvas, float bearing) {
    }
}

OTHER TIPS

We can calculate bearings manually, Bearing between two location can be calculated by

float bearing = mLoc.bearingTo(mLocTarget);
if(bearing<0){
bearing+=360;
}

Normal compass bearing can be calculated using sensors:

float newDirection=0;
if(mSensors!=null)
newDirection=-mSensors[0];
if((newDirection-mCurDirection)> 180)
newDirection-=360;
else if((mCurDirection-newDirection)> 180)
newDirection+=360;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top