2012-01-11 19 views
11

Aslında, MKMapPoints için x ve y koordinatlarındaki maks ve dk noktası arasındaki mesafeyi hesaplamaya çalışıyorum. Bunun için Parametreleri değiştirdiğimde MKMetersBetweenMapPoints neden farklı sonuçlar veriyor?

, ben bu (y ekseninde maksimum mesafe) yapıyorum:

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); 

ben konsolda 18997878.291251 olsun. Ben mesafesi hesaplamasını değiştirebilir Ama ne zaman:

dist = MKMetersBetweenMapPoints(test1, test2); 

Ben bu yüzden fark ne anlamıyorum, 18873651.664238 olsun. X ve y eksenlerindeki maksimum mesafe değerlerini elde etmek için doğru şeyi yapıp yapmadığımı bile bilmiyorum.

Herhangi bir yardım için teşekkür ederiz.

+1

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

+0

should günlük satırı NSLog (@ "Distance% f", dist); – Damo

+0

Üzgünüm, bir yazım hatası. Değişken adı dist. (Düzeltilmiş) – FranciscoAlexis

cevap

4

Sanırım bir algoritma problemi. Belli bir hassasiyet elde edildiğinde duran bir tür yaklaşım. Bu yüzden orada bir değişim yok. Kullanarak MKMapPoints olmadan harita üzerinde iki nokta arasındaki mesafeyi almak için örnek kod deneyebilirsiniz:

- (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; 
    } 
İlgili konular