CLLocation distanceFromLocation に問題があります。以下のコードは、デバッグに役立つようにフォーマットされており、2 つの新しい場所を明示的に割り当てるなどしています。
コード:
CLLocation *loc = [LightweightLocationTracker sharedLocationTracker].lastLocation;
if (loc)
{
CLLocation *myLoc = [[CLLocation alloc] initWithLatitude:loc.coordinate.latitude longitude:loc.coordinate.longitude];
CLLocation *productLoc = [[CLLocation alloc] initWithLatitude:self.productToView.latitude longitude:self.productToView.longitude];
CLLocationDistance dist = [myLoc distanceFromLocation:productLoc];
NSLog(@"myLoc.coordinate.latitude %f", myLoc.coordinate.latitude);
NSLog(@"myLoc.coordinate.longitude %f", myLoc.coordinate.longitude);
NSLog(@"productLoc.coordinate.latitude %f", productLoc.coordinate.latitude);
NSLog(@"productLoc.coordinate.longitude %f", productLoc.coordinate.longitude);
NSLog(@"dist %f", dist);
NSLog(@"%1.1f km", dist);
}
1 回の TTY の実行:
[] tapped main
[] myLoc.coordinate.latitude 52.369200
[] myLoc.coordinate.longitude 13.941100
[] productLoc.coordinate.latitude 52.364400
[] productLoc.coordinate.longitude 13.360600
[] dist 39542.386770
[] 39542.4 km
別の実行 TTY:
[] myLoc.coordinate.latitude 52.369200
[] myLoc.coordinate.longitude 13.941100
[] productLoc.coordinate.latitude 52.369202
[] productLoc.coordinate.longitude 13.941100
[] dist 0.184915
[] 0.2 km
犯人が見えない…