简体   繁体   English

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

[英]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.

相关问题 obj-C,为什么给我昨天的约会? - obj-C, why does this give me yesterdays date? 为什么即使我将其移出屏幕一半,CALayer的visibleRect方法也始终为我的UIImageView提供相同的宽度? - Why does the visibleRect method of CALayer give me always the same width for my UIImageView even if I move it half out of the screen? 为什么调用glMatrixMode(GL_PROJECTION)在iPhone应用程序中给我EXC_BAD_ACCESS? - Why does calling glMatrixMode(GL_PROJECTION) give me EXC_BAD_ACCESS in an iPhone app? 在将条目插入存在的部分时,为什么UITableView会为我添加另一个部分? - Why does my UITableView add another section for me when I insert an entry into an exist section? (iphone)设置动画时,我可以给图像之间不同的间隔吗? - (iphone) can i give different intervals between images when animating? 为什么-sizeWithFont:在代码和调试器中返回不同的结果? - Why does -sizeWithFont: return different results in code and debugger? 为什么在将Float转换为CGFloat Xcode时会给我一个警告“无法将类型'CGFloat'的值转换为预期的参数类型'UnsafeMutablePointer”? - Why when converting Float to CGFloat Xcode give me a warning “Cannot convert value of type 'CGFloat' to expected argument type 'UnsafeMutablePointer”? symbolicatecrash没有给我自己函数的方法名称 - symbolicatecrash does not give me method names for my own functions 为什么XCode警告我另一个类中的方法可能不存在? - Why does XCode warn me that a method in another class might not exist when it does? 为什么在编辑图像时会得到这些奇怪的结果? - Why am I getting these weird results when editing the image?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM