views:

26

answers:

1

Hi, I'm trying to develop an application that use the GPS and Compass of the iPhone in order to point some sort of pointer to a specific location (like the compass always point to the North). The location is fixed and I always need the pointer to point to that specific location no matter where the user is located. I have the Lat/Long coordinates of this location but not sure how can I point to that location using the Compass and the GPS... any help will be appreciated.

+1  A: 

1) Get your current location (from the GPS)

2) Get the differences in latitude and longitude

3) use the atan2 method to get the angle

i.e. (WARNING: untested code)

CLLocation *targetLocation = [CLLocation alloc] initWithLatitude:1 longitude:2];
CLLocation *sourceLocation = <get from GPS>

double dx = [targetLocation coordinate].latitude - [sourceLocation coordinate].latitude;
double dy = [targetLocation coordinate].longitude - [sourceLocation coordinate].longitude;

double angle = atan2(dx, dy);

You might have to tweak that to get it to compile but the idea is there!

deanWombourne
after i get angle. How can i use current heading achieve by compass.
Jesse
I just using current heading - angle. then rotate arrow by(current heading -angle) but i can't get the right answer?
Jesse