The easiest solution is this:
1. Get your lat/lon. (lat1/lon1)
2. Get the lat/lon of the object (lat2/lon2).
3. Calculate the absolute bearing from lat1/lon1 to lat2/lon2.
4. Get the compass bearing of your device. Subtract the bearing of the device from the bearing of the object. This is your "relative bearing".
Code for step 4 is this:
Code:
- (float)relativeBearingFromBearing:(float)bearingOfLocation:(float)bearingOfCompassHeading
{
// bearingOfLocation is the rhumb line from where you are physically.
// bearingOfCompassHeading is the direction your compass is pointing physically.
//Example:
//if object is 0 deg (N) of you and you are facing west (-270), then object is actually
//90 deg to your right.
float relativeBearing = (bearingOfLocation + bearingOfCompassHeading);
if (relativeBearing > 360) {
//Correct it.
relativeBearing -= 360;
}
return relativeBearing;
}
If the bearing is +/- say 20 degrees, then the object is roughly in front of you.
Hope that helps.
Cheers,
Jase