嘿我试图计算iPhone上的1个点到另一个点的距离(水平)我不知道怎么样
答案 0 :(得分:0)
您需要创建CLLocation实例,并调用方法进行计算。
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];
如果你想要两点之间的距离,你应该记住Pitagora:
CGPoint pointA, pointB;
double distancesInPoints = sqrt((pointA.x-pointB.x)*(pointA.x-pointB.x) + (pointA.y-pointB.y)*(pointA.y-pointB.y));