How can I get the direction of travel (N, NE, E, SE, S, SW, W, NW) on an iPhone using only information from the GPS (longitude and latitude)?
I do not want to use the compass because it isn't always accurate.
How can I get the direction of travel (N, NE, E, SE, S, SW, W, NW) on an iPhone using only information from the GPS (longitude and latitude)?
I do not want to use the compass because it isn't always accurate.
Just grab the current coordinates at two separate instants and subtract them. Here's some pseudocode (sorry, I don't speak Objective-C):
start <- get current position
wait some time
end <- get current position
direction = end - start
This will give you a vector that points in the current direction. To get it as an angle you can use the vector dot product.
product <- start.lat * end.lat + start.lng * end.lng
start_length <- sqrt(start.lat^2 + start.lng^2)
end_length <- sqrt(end.lat^2 + end.lng^2)
angle <- arccos(product/(start_length * end_length))
Given the angle, you can easily get the cardinal direction. Just see which one is nearest.