views:

343

answers:

3

Thanks,

EDIT///

Converting the outcome to radians gives me a lat of 5.6xxxxxxxxxxxxxx .I have a feeling this bug has something to do with conversions but its not THAT simple.

The equation is correct, it just.. outputs wrong..

+1  A: 

for long distance: http://www.dtcenter.org/met/users/docs/write_ups/gc_simple.pdf but for short distance You can try simple 2d math to simulate "classic" compass using: http://en.wikipedia.org/wiki/Compass#Using_a_compass. For example you can get pixel coordinates from points A and B and find angle between line connecting those points and vertical line.

also You probably should consider magnetic declination: http://www.ngdc.noaa.gov/geomagmodels/Declination.jsp

//edit:

I was trying to give intuitive solution. However calculating screen coordinates from long/lat wouldn't be easy so You probably should use formulas provided in links.

Maciek Sawicki
I'm not really looking to draw a compass as such, I more so want to do a check to see if the direction I am facing is the same direction the location is in. getbearing() wont work as it won't update when I'm not moving. Assume that the user is stationary.
Ulkmun
exactly getbearing isn't useful in this case, use getOrientation() instead. rotation over z axis is azimuth. However reading device orientation is probably the easiest part of this problem.
Maciek Sawicki
Yes, Android knows where I am, the other location and it knows my bearing but I want it to recognise when my bearing is in the same direction as the location. How would I go about doing that?
Ulkmun
it's just math, but If You need some code there is some JS on this site: http://www.movable-type.co.uk/scripts/latlong.html or http://www.ig.utexas.edu/outreach/googleearth/latlong.html
Maciek Sawicki
You've answered my question partly, I've updated the question to reflect the new info you've provided
Ulkmun
A: 

Maybe its because I don't know javascript, but don't you have to do something like

currlat = Math.toRadians(currlat);

to actually change the currlat value to be radians.

Jay R.
It's java. not JAvascript. Also I've already said I've tried Radians + Degree conversions.
Ulkmun
Ok. In the code pasted above Math.toRadians(currlat) won't actually change currlat's value. Just clearing it up for me, sorry.
Jay R.
A: 

Problem was no matter what I piped in java would output in Radians, Trick was to change everything to Radians and then output came in radians, convert to degrees.

Ulkmun