Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qibla compass in Android [duplicate]

I have try much but can not make Qibla compass for my application. I can't understand what I do. I need Qibla compass that works perfectly.

like image 238
Parag Chauhan Avatar asked Jun 04 '12 19:06

Parag Chauhan


People also ask

How do I find the Qibla direction on my phone?

Just go to the address g.co/QiblaFinder on your smartphone and move the camera until the Kaaba symbol shows up, floating in space.

Which sensor is required for Qibla direction?

Because each region does not have the same degree of orientation, the HMC 5883L sensor should be operated by including GPS as a point of coordinate, so that the sensor can work by directly reading the angle of the direction of the Qibla.

How do I find the qibla on Google Maps?

Once the application is open, type Kaaba in the search box. Next the screen will display the results of the location of the Kaaba. Zoom out until you can point from your location and the Kaaba can fit in one screen. Point the top of the phone until the points on the screen face the Kaaba.


1 Answers

You know the location of Mecca and you know the users current location (if you have GPS or some other location provider). The bearing is given by this formula, latitudes and longitudes should 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 could also explore the Location.bearingTo() method, see here.

like image 199
Simon Avatar answered Oct 04 '22 14:10

Simon