2012-01-11 10 views
11

私は実際にMKMapPointsのx座標とy座標の最大点と最小点の距離を計算しようとしています。そのためにパラメータを交換すると、MKMetersBetweenMapPointsが私に異なる結果をもたらすのはなぜですか?

、私はこの(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

:http://stackoverflow.com/questions/5558854/order-of-cllocation-objects-in-distancefromlocation – Anna

+0

べきログ行は NSLog(@ "Distance%f"、dist)です。 – Damo

+0

申し訳ありませんが、タイプミスです。変数名はdistです。 (修正済み) – FranciscoAlexis

答えて

4

これはアルゴリズムの問​​題だと思います。特定の精度が達成されたときに停止する何らかの近似。だからこそそこに転流がないのです。あなたはMKMapPointsを使用せずに、マップ上の2点間の距離を取得するサンプルコードを試すことができます。

関連
- (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; 
    } 
関連する問題