2010-12-14 4 views
0

Ich habe die schwierigste Zeit versucht herauszufinden, warum distanceFromLocation nicht den richtigen Abstand für zwei CLLocations berechnet. Das berechnete Ergebnis ist eine Nummer WAY größer als die tatsächliche Entfernung, aber die zwei Standorte scheinen gültige Standorte zu sein.DistanceFromLocation produziert extrem großen (falschen) Abstand

Zunächst einmal sind hier die zwei Standorte:

LAGE 1: < 44,56697840, -69,55759810> +/- 0.00m (Geschwindigkeit -1,00 mps/Kurs -1,00) @ 2010-12 -13 21:12:03 -0500
LOCATION 2: < 44,31400400, -69,79157000> +/- 0.00m (Geschwindigkeit -1,00 mps/Kurs -1,00) @ 2010-12-13 21.12: 03 -0500

Und hier ist der Code, wo Location1 und Location2 deklariert werden. Ich habe festgestellt, dass diese die richtigen Werte sind, aber ich kann immer noch nicht das herauszufinden

CLLocation *newLocation = [[CLLocation alloc] 
    initWithLatitude:[latitude doubleValue] 
    longitude:[longitude doubleValue]]; 
    // CURRENT LOCATION (OR SEARCHED LOCATION) 

double dLat = 0; 
int tmpDistance = 0; 
id returnId = nil; 

id tmp = [featuredResults objectAtIndex:i]; 
CLLocation *newLocation2 = [[CLLocation alloc] 
    initWithLatitude:[[tmp valueForKey:@"lat"] doubleValue] 
    longitude:[[tmp valueForKey:@"lng"] doubleValue]]; 

dLat = [newLocation distanceFromLocation:newLocation2]; 

Der Wert, den ich für DLAT bekommen ist 330.707.027, die Art und Weise falsch ist. Weiß jemand, wo ich vielleicht falsch liege? Vielen Dank!

+0

willst du nicht den Abstand von newLocation2 berechnen? – jakev

Antwort

0

Dieser Code-Test auf dem in der Frage basiert gibt etwa 33.669 Meter:

CLLocation *newLocation = [[CLLocation alloc] 
    initWithLatitude:44.56697840 longitude:-69.55759810]; 

CLLocation *newLocation2 = [[CLLocation alloc] 
    initWithLatitude:44.31400400 longitude:-69.79157000]; 

double dLat = [newLocation distanceFromLocation:newLocation2]; 

NSLog(@"distance = %f meters", dLat); 

[newLocation release]; 
[newLocation2 release]; 

Ausgang:

Entfernung = 33.669,002406 Meter

Vielleicht protokollieren Sie DLAT mit etwas anderes als %f?