My question is not really for Nutiteq SDK, it is for help from people who use CartoDB SDK on map rotation.
See bellow my code. I doesn't work as I want : rotate map to show the north up to the device or show the deplacement direction up to the device.
If some of you, has already use compass on his map using CartoDB or nutiteq SDK, his help would be of great use to me.
float R[] = new float[9];
float I[] = new float[9];
boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
if (success) {
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);
azimutRadian = orientation[0]; // orientation contains: azimut, pitch and roll
}
if (azimutRadian != null && curLocation != null) {
azimutDegree = (float)(Math.toDegrees(azimutRadian)+360)%360;//I convert radian to degree, to be sure the value is positive and get modulo
geoField = new GeomagneticField(
Double.valueOf(curLocation.getLatitude()).floatValue(),
Double.valueOf(curLocation.getLongitude()).floatValue(),
Double.valueOf(curLocation.getAltitude()).floatValue(),
System.currentTimeMillis()
);
h.post(new Runnable() {
@Override
public void run() {
mapView.getOptions().setRotatable(true);
float curBear = lastKnownedLocation.bearingTo(curLocation);
declinaison = geoField.getDeclination();
if(prefMapOrientation.toUpperCase().equalsIgnoreCase("NORTH-IS-UP")) {// the north is up on the device
maprotation = ((azimutDegree + declinaison)+360)%360;
mapView.setMapRotation(-maprotation, baseProjection.fromWgs84(new MapPos(curLocation.getLongitude(), curLocation.getLatitude())), 0);
}
else { // the up of device shows the deplacement direction
maprotation = ((azimutDegree + declinaison - curBear)+360)%360;
mapView.setMapRotation(-maprotation, baseProjection.fromWgs84(new MapPos(curLocation.getLongitude(), curLocation.getLatitude())), 0);
}
lastAzimutDegree = azimutDegree;
mapView.getOptions().setRotatable(false);
}
});
}