MapView and rotation : the north or deplacement direction

42 views
Skip to first unread message

rfidt...@gmail.com

unread,
Feb 28, 2017, 5:12:36 AM2/28/17
to Nutiteq-dev
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);
}
});
}

aa...@cartodb.com

unread,
Mar 1, 2017, 6:52:06 AM3/1/17
to Nutiteq-dev, rfidt...@gmail.com
Hey,

You should check out our open source mobile-android-maps-app, it's been solved there: https://github.com/CartoDB/mobile-android-maps-app


Best wishes,
Aare
CARTO Mobile
Reply all
Reply to author
Forward
0 new messages