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
Simon source share