[英]Why does MKMetersBetweenMapPoints give me different results when I swap the parameters?
I'm actually trying to calculate the distance between the max and min point in the x and y coordinates for the MKMapPoints
. 我实际上是在计算
MKMapPoints
的x和y坐标中最大和最小点之间的距离。
For that, I'm doing this (max distance in y axis): 为此,我这样做(y轴的最大距离):
MKMapPoint test1, test2;
double dist;
test1.x = 0.0;
test1.y = 0.0;
test2.x = 0.0;
test2.y = MKMapSizeWorld.height;
dist = MKMetersBetweenMapPoints(test2, test1);
NSLog(@"Distance %f",dist);
I get 18997878.291251 in the console. 我在控制台中得到18997878.291251。 But when I change the distance calculation to:
但是当我将距离计算更改为:
dist = MKMetersBetweenMapPoints(test1, test2);
I get 18873651.664238, so I don't understand what's the difference. 我得到18873651.664238,所以我不明白有什么区别。 I don't even know if I'm doing the right thing to get the max values of distance in the x and y axes.
我甚至不知道我是否做正确的事情来获得x和y轴的最大距离值。
Any help will be appreciated. 任何帮助将不胜感激。
I guess it's an algorithm problem. 我想这是一个算法问题。 Some kind of approximation that stops when a certain precision is achieved.
某种近似值在达到一定精度时停止。 That's why no commutation there.
这就是为什么没有减刑的原因。 You can try sample code to get distance between two points on map without using MKMapPoints:
您可以尝试使用示例代码在不使用MKMapPoints的情况下获取地图上两点之间的距离:
- (float) distanceToLPU {
useDelegate
CLLocationCoordinate2D pointACoordinate = appDelegate.usrLoc;
CLLocation *pointALocation = [[CLLocation alloc] initWithLatitude:pointACoordinate.latitude longitude:pointACoordinate.longitude];
CLLocationCoordinate2D pointBCoordinate;
pointBCoordinate.latitude = [self.latitude doubleValue];
pointBCoordinate.longitude = [self.longitude doubleValue];
CLLocation *pointBLocation = [[CLLocation alloc] initWithLatitude:pointBCoordinate.latitude longitude:pointBCoordinate.longitude];
float distanceMeters = [pointALocation distanceFromLocation:pointBLocation];
[pointALocation release];
[pointBLocation release];
NSString *dist = [NSString stringWithFormat:@" (%.0f м)", distanceMeters];
NSLog(@"Distance to this LPU:%@", dist);
return distanceMeters;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.