I have 2 sets of coordinates. The user has to travel from one location to the other. What would be the best means to show directions between the 2 coordinates. I have calculated the distance between 2 points. I have also found the angle between the 2 coordinates.
p1 = CGPointMake(coordinatesInDisplacement.latitude, coordinatesInDisplacement.longitude);
p2 = CGPointMake(coordinatesInDistance.latitude,coordinatesInDistance.longitude);
f = [self pointPairToBearingDegrees:p1 secondPoint:p2];
- (CGFloat) pointPairToBearingDegrees:(CGPoint)startingPoint secondPoint:(CGPoint) endingPoint
{
CGPoint originPoint = CGPointMake(endingPoint.x - startingPoint.x, endingPoint.y - startingPoint.y); // get origin point to origin by subtracting end from start
float bearingRadians = atan2f(originPoint.y, originPoint.x); // get bearing in radians
float bearingDegrees = bearingRadians * (180.0 / M_PI); // convert to degrees
bearingDegrees = (bearingDegrees > 0.0 ? bearingDegrees : (360.0 + bearingDegrees)); // correct discontinuity
return bearingDegrees;
}
Is finding angle without direction any use for navigation. Is finding direction, with the provided 2 coordinates only, possible?
But I think that wouldn't just be enough. What all details should I(or it is possible to) provide the user from IOS device to correctly reach from the starting point to the destination point.
Edit: I have 2 locations, one is in England and the other in Spain. If I am travelling from Spain to England,
is it possible to get directions like, 30°N 20°W. i.e. I have to travel 30°N 20°W from Spain to reach England.
Is the bearing angle, same as the angle in degrees I mentioned just above.
The "heading/bearing" is the angle between a line pointing north and a line pointing where you are going. So if the target is directly north of you the heading is 0°. If the target is directly east of you the heading is 90°. Since the heading is always measured from north you don't say 90°N. If you have that as a measurement most geographers would think you meant 30° up from the equator.
Another question here on StackOverlow shows an Objective-C implmentation of the Haversine formula. When near the equator you can use the faster formula and not be too wrong, but with the speed of iOS devices unless you are doing a million of these calculations you might as well use the more accurate one.