当我交换参数时,为什么MKMetersBetweenMapPoints会给我不同的结果?

时间:2012-01-11 14:38:22

标签: iphone ios google-maps geolocation mapkit

我实际上是在计算MKMapPoints的x和y坐标中最大和最小点之间的距离。

为此,我这样做(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);

我在控制台中获得了18997878.291251。但是,当我将距离计算更改为:

dist = MKMetersBetweenMapPoints(test1, test2);

我得到18873651.664238,所以我不明白有什么区别。我甚至不知道我是否做正确的事情来获得x和y轴的最大距离值。

任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:4)

我猜这是一个算法问题。某种近似值在达到一定精度时停止。这就是为什么没有减刑的原因。您可以尝试使用示例代码在不使用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;
    }