0

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

wafflez180
  • 55
  • 1
  • 1
  • 7

1 Answers1

0

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));
Onik IV
  • 5,007
  • 2
  • 18
  • 23