views:

54

answers:

2

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?

+2  A: 

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.

Josh Hinman
ok, thank to that awesome page, I calculate the correct bearing; unfortunately, I tried different formulas to find the difference, but I didn't find the right one: could you please point me to the right operation?
Giordano Scalzo
ok, found it, and now it works! Thanks a lot
Giordano Scalzo
A: 

potresti spiegarti meglio, magari mettendo un piccolo source code di un'app che servirebbe moltissimo anche a me!! grazie

fast