0

I am developing a project in augmented reality where a compass shows the direction to the destination.That works fine but i want to check whether the current heading is pointing towards the destination or not. Can any one suggest me a method to do it? I have searched a lot in Google couldn't find any method?

Thanks in advance

rahul raj
  • 597
  • 1
  • 4
  • 15
  • So you basically want to detect if the device heads to the North? –  Aug 10 '12 at 13:43
  • Y i want to check whether heading is towards north or not .I want to check whether the device is pointing towards the location . – rahul raj Aug 10 '12 at 13:46

1 Answers1

0

You need the absolute bearing from your location to your target location

Unfortunately CLLocation doesn't have a call for this but you can find the algo in this question.

CLLocation Category for Calculating Bearing w/ Haversine function

So lets say the bearing is 90 degrees

Then you get the phone bearing to north.

While you are getting location updates you also have course update with CLLocation.

The course might also be 90 degrees

SO find the difference between the two, 90 - 90 = 0! you are dead on target :) You will need to rationalise the numbers to 0 - 360 in the event say you are facing north (0 degrees) and your target is behind you (180 degrees) resulting in -180. If you end up with a negative number just add 360.

I find the magnetic field compass to be very very fidgety, so it looks much nicer if you have some sort of exponential moving average for changes in the phones bearing.

Community
  • 1
  • 1
Pork 'n' Bunny
  • 6,740
  • 5
  • 25
  • 32