Hey I'm trying to calculate the distance of 1 spot to another on the iPhone (horizontally) Im not sure how
Asked
Active
Viewed 53 times
0
-
open CGPointExtension.h in the cocos2d project, you'll find ccpDistance and others – CodeSmile Nov 08 '14 at 18:37
1 Answers
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
-
Of course you need Core Location framework to you project, and ViewController. – Onik IV Nov 08 '14 at 18:18
-
1you assume geographic locations were asked for, more likely it's just CGPoint distances – CodeSmile Nov 08 '14 at 18:37