i have an app in which i want to do some custom compass functionality suppose i have location A and location B i mark my location (Location A) then i move to some distance my compass should point to Location A wherever i can move i am referencing qiblacompass functionality but its not pointing to location A when i move to other location here is my code
public static double getDirectionFromNorth(double degLatitude,
double degLongitude) {
final double direction_LATITUDE = Math.toRadians(angle_lat);
double direction_LONGITUDE = Math.toRadians(angle_lng);
double latitude2 = Math.toRadians(degLatitude);
double longitude = Math.toRadians(degLongitude);
double soorat = Math.sin(direction_LONGITUDE - longitude);
double makhraj = Math.cos(latitude2) * Math.tan(direction_LATITUDE)
- Math.sin(latitude2) * Math.cos(direction_LONGITUDE - longitude);
double returnValue = Math.toDegrees(Math.atan(soorat / makhraj));
if (latitude2 > direction_LATITUDE) {
if ((longitude > direction_LONGITUDE || longitude < (Math
.toRadians(-180d) + direction_LONGITUDE))
&& (returnValue > 0 && returnValue <= 90)) {
returnValue += 180;
} else if (!(longitude > direction_LONGITUDE || longitude < (Math
.toRadians(-180d) + direction_LONGITUDE))
&& (returnValue > -90 && returnValue < 0)) {
returnValue += 180;
}
}
if (latitude2 < direction_LATITUDE) {
if ((longitude > direction_LONGITUDE || longitude < (Math
.toRadians(-180d) + direction_LONGITUDE))
&& (returnValue > 0 && returnValue < 90)) {
returnValue += 180;
}
if (!(longitude > direction_LONGITUDE || longitude < (Math
.toRadians(-180d) + direction_LONGITUDE))
&& (returnValue > -90 && returnValue <= 0)) {
returnValue += 180;
}
}
// ***
return returnValue;
}
where angle_lat and angle_lng is my location A latitude,longitude and degLatitude, degLongitude are those when i move it gets lat,lng from my GPS
anyone please tell me what is fault in this code or i any other method to achieve my task?