Search code examples
iphonecocoa-touchcompass-geolocationimage-rotation

Rotate an image to direct to a well know point using compass heading


As a proof of concept, I want to create an application that retrieve the current coordinates, calculate the direction towards an another point and, using compass, rotate an arrow image to direct to that point in space.

I know how to retrieve current coordinate and to rotate the image through CGAffineTransformMakeRotation, but I haven't find a formula to calculate the correct angle.

Any hints?


Solution

  • First you need to calculate a bearing. This page gives a neat formula for doing that:

    http://www.movable-type.co.uk/scripts/latlong.html

    Then, you can do some simple arithmetic to find the difference between that bearing and the heading the iPhone is pointed towards. Rotate your image by that difference.