2012-06-04 3 views
6

Ich habe viel versucht, aber kann nicht qibla Kompass für meine Anwendung machen. Ich kann nicht verstehen, was ich tue. Ich brauche qibla Kompass, der mich perfekt macht. Dank paragQibla Kompass in Android

+1

Sie brauchen viel mehr spezifisch. – Hassan

+0

@Hassan ja Hassan –

+0

Versuchen Sie, einen zu programmieren? Mit was hast du Probleme? Was hast du probiert? – CaseyB

Antwort

7

Sie kennen den Standort von Mekka und Sie kennen den aktuellen Standort des Benutzers (wenn Sie GPS oder einen anderen Standortanbieter haben). Die Peilung ist durch diese Formel gegeben, Breiten und Längen sollten im Bogenmaß angegeben werden.

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 ist die Richtung in Grad.

Sie können auch die Location.bearingTo() -Methode erkunden.

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

As-Salaam-Alaikum

+0

Ich bekomme erro: 'Kann toDeg() auf dem primitiven Typ double nicht aufrufen – Salim

+2

Gelöst es' float brng = (float) Math.toDegrees (Math.atan2 (y, x)); ' – Salim