Angle to Mecca from current location with iPhone compass

0 votes

I am developing an iPhone application that will display both the North and Qibla directions. I am displaying the North direction with the aid of CLLocationManager and updating it with CLHeading as newHeading. magneticHeading, And using the following code, I am indicating the Qibla direction.

double A = MECCA_LONGITUDE - lon;
double b = 90.0 - lat;
double c = 90.0 - MECCA_LATITUDE;
NSLog(@"tan -1( sin(%f) / ( sin(%f) * cot(%f) - cos(%f) * cos(%f)))", A, b, c, b, A);
double qibAngle =  atan(sin(A) /( sin(b) * (1 / tan(c)) - cos(b) * cos(A) ));
NSLog(@"qib Angle- %f",qibAngle);
qibla.transform = CGAffineTransformMakeRotation(qibAngle * M_PI /180);

I'm getting the angle here, but when I rotate the device, the angle does not change. Could someone please help me? I know that I need to do something with the title, but I'm not sure what.

Sep 27, 2022 in IOS by Soham
• 9,710 points
434 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes
The code you posted, I think, calculates the angle between the location's geographic north and the direction toward Mecca. Now all you have to do is consider the user's heading.

Consider a situation where the user is facing directly due East and Mecca is directly due West. The qibla angle must be -90 degrees because tan returns +/-90 degrees. The adjustment should now be clear: to find the angle that the user must turn to face Mecca, you must subtract 90 degrees from the qibla's angle with regard to geographical north (-90).

In other words, you need to "undo" the user's deviance, and you accomplish this by

the user's heading, as it relates to the geographic north, is known as the qibla angle.

Now that the math is out of the way, you must watch for heading changes and recalculate the qibla angle as necessary. Remember to use the trueHeading attribute, too.
answered Sep 28, 2022 by Rahul
• 9,680 points

edited Mar 5

Related Questions In IOS

0 votes
1 answer

How to get rid of blank space from iPhone notch on web page

You should be looking for the meta-setting ...READ MORE

answered Nov 8, 2022 in IOS by Rahul
• 9,680 points
2,275 views
0 votes
0 answers

How to access and read a file on a USB drive from IOS? (Connected via OTG cable to iPhone)

Can I access a text file on ...READ MORE

Nov 7, 2022 in IOS by Soham
• 9,710 points
675 views
0 votes
1 answer

Is it possible to run .APK/Android apps on iPad/iPhone devices?

It is not possible to run Android ...READ MORE

answered Sep 20, 2022 in IOS by Aditya
• 7,680 points
4,860 views
0 votes
1 answer

How is a rounded rect view with transparency done on iphone?

view.layer.cornerRadius = radius; The difficult technique is to ...READ MORE

answered Sep 22, 2022 in IOS by Rahul
• 9,680 points
1,207 views
0 votes
1 answer

Is there a way to to check if a picture was taken on that iPhone?

Actually, the model and manufacturer information is ...READ MORE

answered Sep 22, 2022 in IOS by Rahul
• 9,680 points
781 views
0 votes
0 answers

How to connect iphone to a local server running on mac?

I am running a django server at ...READ MORE

Sep 22, 2022 in IOS by Soham
• 9,710 points
827 views
0 votes
0 answers

iPhone system font

What is the name of the default ...READ MORE

May 16, 2022 in Others by Kichu
• 19,040 points
580 views
0 votes
1 answer

iPhone system font

The iPhone system interface uses Helvetica or ...READ MORE

answered Sep 20, 2022 in Others by Aditya
• 7,680 points
1,559 views
0 votes
1 answer

Getting country calling prefix

For a class that offers both this ...READ MORE

answered Sep 20, 2022 in Others by Aditya
• 7,680 points
963 views
0 votes
1 answer

Detecting iPhone 6/6+ screen sizes in point values

The device screen will be the first ...READ MORE

answered Sep 22, 2022 in IOS by Rahul
• 9,680 points
1,070 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP