Qibla Compass on Android

I try a lot, but I can not make a qibla compass for my application. I can’t understand what I’m doing. I need a qibla compass that works great. thanks parag

+6
source share
1 answer

You know the location of Mecca, and you know the current location of users (if you have a GPS or some other location provider). The bearing is given by this formula, latitude and longitude must be in radians.

float lonDelta = (lon2 - lon1); float y = Math.sin(lonDelta) * Math.cos(lat2); float x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lonDelta); float brng = Math.atan2(y, x).toDeg(); 

brng is the direction in degrees.

You can also learn the Location.bearingTo () method.

http://developer.android.com/reference/android/location/Location.html#bearingTo (android.location.Location)

Assalam alaikum

+7
source

Source: https://habr.com/ru/post/917395/


All Articles