[英]finding the distance from point A to point B for iPhone
嘿,我正在尝试计算iPhone上1个点到另一个点的距离(水平),我不确定
Hi you need to create to instance of CLLocation, and call the methods to calculate. 嗨,您需要创建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];
If you want distances between two points, you should remember Pitagora: 如果需要两点之间的距离,则应记住Pitagora:
CGPoint pointA, pointB;
double distancesInPoints = sqrt((pointA.x-pointB.x)*(pointA.x-pointB.x) + (pointA.y-pointB.y)*(pointA.y-pointB.y));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.