finding the distance from point A to point B for iPhone

56 views Asked by At

Hey I'm trying to calculate the distance of 1 spot to another on the iPhone (horizontally) Im not sure how

1

There are 1 answers

2
Onik IV On BEST ANSWER

Hi you need to create to instance of CLLocation, and call the methods to calculate.

CLLocation *locationOne = [[CLLocation alloc] initWithLatitude:[point coordinate].latitude longitude:[point coordinate].longitude];
CLLocation *locationTwo = [[CLLocation alloc] initWithLatitude:[secondPoint coordinate].latitude longitude:[secondPoint coordinate].longitude];
double distanceInMeters = [locationOne distanceFromLocation:locationTwo];

If you want distances between two points, you should remember Pitagora:

CGPoint pointA, pointB;
double distancesInPoints = sqrt((pointA.x-pointB.x)*(pointA.x-pointB.x) + (pointA.y-pointB.y)*(pointA.y-pointB.y));