I have a coordinate from Core Location and want to calculate the co-ordinate given a bearing and a distance, say in km.
I think this is the formula from here. http://www.movable-type.co.uk/scripts/latlong.html
Formula:
lat2 = asin(sin(lat1)cos(d/R) + cos(lat1)sin(d/R)cos(θ))
lon2 = lon1 + atan2(sin(θ)sin(d/R)cos(lat1), cos(d/R)−sin(lat1)sin(lat2))
d/R is the angular distance (in radians), where d is the distance travelled and R is the earth’s radius
I have the following code.
CLLocationCoordinate2D linecoordstart;
linecoordstart = [[existingpoints objectAtIndex:i] coordinate];
NSString *bearing = [[existingpoints objectAtIndex:i] heading];
NSString *distance = [[existingpoints objectAtIndex:i] distance];
CLLocationCoordinate2D sourceCoordinate;
sourceCoordinate = [[existingpoints objectAtIndex:i] coordinate];
NSLog(@"%f,%f",sourceCoordinate.latitude,sourceCoordinate.longitude);
float lat2;
int d = 5;
int R = 6371;
lat2 = asin(sin(sourceCoordinate.latitude)cos(d/R) + cos(sourceCoordinate.latitude)sin(d/R)cos(180));
NSLog(@"%f",lat2);
I want to be able to pass it a bearing which is currently an NSString and the distance. I cannot work out how to use the Math.h functions for the life of me!