This is my code so far and is changing the rotation of the marker regarding the position of the tablet.
float[] mGravity;
float[] mGeomagnetic;
Float azimut;
Marker Mymarker;
MarkerOptions MyMarkerOption = new MarkerOptions();
public void onSensorChanged(SensorEvent event) {
if(GotLocation){
if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
mGravity = event.values;
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
mGeomagnetic = event.values;
if (mGravity != null && mGeomagnetic != null) {
float R[] = new float[9];
float I[] = new float[9];
boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
MyLocation = new LatLng(currentLatitude, currentLongitude);
if (success) {
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);
azimut = orientation[0];
float azimuthInRadians = orientation[0];
float azimuthInDegress = (float)(Math.toDegrees(azimuthInRadians)+360)%360;
if(location_marker == 0){
MyMarkerOption.position(MyLocation);
Mymarker = map.addMarker(MyMarkerOption);
location_marker++;
}
Mymarker.setPosition(MyLocation);
Mymarker.setRotation(azimuthInDegress);
Mymarker.setFlat(true);
}
}
}
}
I would like that the rotation of the marker changes regarding a given lat-long position. So I guess that now the algorithm is calculating the azimuthInDegress regarding the tablet. I would like that it calculates it regarding a given point.
I found this thread where someone was asking the same thing, but I do not know how to implement this solution for my code..The thread is also 5 years old so maybe there is another solution right now.