In my app I have a latitude-longitude of 1 fix location. Now user with iPhone device can move anywhere and even he rotate his device, the arrow (some uiimageview) should poi
Try this example. Its in C# Xamarin tho :) "double heading" is the CLHeading.MagneticHeading from the eventobject in CLLocationManager.UpdatedHeading.
void UpdateCompass(Location origin, Location target, double heading)
{
var angle1 = GetAngleBetweenPoints(origin, target);
var angle2 = GetAngleFromHeading(heading);
var radian = Math.PI * (angle1 + angle2) / 180.0;
CompassArrow.Transform = CGAffineTransform.MakeRotation((nfloat)radian);
}
double GetAngleBetweenPoints(Location origin, Location target)
{
var n = 270 - (Math.Atan2(origin.Latitude - target.Latitude, origin.Longitude - target.Longitude)) * 180 / Math.PI;
return n % 360;
}
double GetAngleFromHeading(double heading)
{
var radians = -heading / 180.0 * Math.PI;
return radians * (180.0 / Math.PI);
}