1

我在使用 CLLocation distanceFromLocation 时遇到了一些问题。我有下面的代码,格式化以帮助调试,显式分配两个新位置等。无论哪种方式,两个几乎相同的位置都会导致巨大的差距,但只是有时。

代码:

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

一次运行 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

没有看到罪魁祸首...

4

1 回答 1

3

好吧,distanceFromLocation返回米。所以30k的东西只是30km。对我来说听起来完全合法。

于 2012-08-02T22:37:33.390 回答