nazim corakli
nazim corakli

Reputation: 197

compass shows me the north normally. but I want from it for showing another way (?)

I am making an app with c# for my windows phone 7. I want to use compass for showing me the qibla direction (or which way I want). how can I make it? I can calculate the degrees of qibla direction from my location with lang and latitute.(for example result is 150 degress east of north)

but then, I cannot draw the direction line for it.it shows north, not my way which I want. so now I am using this code for drawing line:

magneticLine.X2 = magneticLine.X1 - (200 * Math.Sin(MathHelper.ToRadians((float)compassReading.MagneticHeading)));

magneticLine.Y2 = magneticLine.Y1 - (200 * Math.Cos(MathHelper.ToRadians((float)compassReading.MagneticHeading)));

can you help me about how I can make this. thanks.

Upvotes: 2

Views: 997

Answers (1)

Jeremiah Isaacson
Jeremiah Isaacson

Reputation: 340

The way you have it built currently you are merely using the center of the screen as the point of origin and then rendering a line that is always 200 pixels in length. You need to adjust/tamper with the degree reading prior to drawing your line (that's why it's not pointing in the correct direction for you).

Also, once you have something you think is correct, use the Windows Phone emulator to plot GPS points around Kaaba in Mecca (i.e. Make a circle of points around the Kaaba and then run a simulation). That will allow you to see if your solution will work for individuals in a 360* radius correctly.

Furthermore, this toolkit on Augmented Reality may help you as it does some of the math for you when calculating the direction based on your GPS location: http://gart.codeplex.com/

I hope this helps. If you are still stuck after the above reading, I can code it out for you so you have a better understanding.

Lastly, scope this out: http://www.jeffblankenburg.com/2011/11/04/31-days-of-mango-day-4-compass/

It's a tutorial on how to make a compass with working source code to download at the bottom of the article. Good luck!

Upvotes: 1

Related Questions