ios - 使用 CLLocation 计算距离 iOS MapKit

标签 ios mapkit

我正在尝试使用纬度和经度查找以英里为单位的距离。我有以下方法:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation
{
    if(!newLocation) return; 

    if ((oldLocation.coordinate.latitude != newLocation.coordinate.latitude) &&
        (oldLocation.coordinate.longitude != newLocation.coordinate.longitude))
    {



        CLLocation *loc1 = [[CLLocation alloc] initWithLatitude:oldLocation.coordinate.latitude longitude:oldLocation.coordinate.longitude];
        CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.latitude longitude:newLocation.coordinate.latitude];

        CLLocationDistance distance = ([loc2 distanceFromLocation:loc1]) * 0.000621371192;

        //distance = distance; 

        NSLog(@"Total Distance %f in miles",distance);
    }

}

出于某种原因,它打印出类似 5678.32 英里的内容。该位置几乎是静止的,根本没有移动。

最佳答案

CLLocation *loc2 = [[CLLocation alloc] initWithLatitude:newLocation.coordinate.(!!!!!)latitude longitude:newLocation.coordinate.(!!!!!)latitude];

关于ios - 使用 CLLocation 计算距离 iOS MapKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6685553/

相关文章:

ios - 使用多个转场 |如何使用 Cell 数据执行特定的 Segues

iphone - 我们可以在 iPhone 设备上自动安装任何 .deb/.ipa 文件吗?

ios - Swift ios alamofire put请求错误Thread 1 : signal SIGABRT at

iphone - “保持” UIButton 行为 - `Touch Cancelled` 控制状态阻止进一步的控制状态

swift - 通过 rightCalloutAccessoryView 访问自定义 MKAnnotation 数据时出现问题

ios - 在 map 上隐藏一个特定的街道名称

iOS MapKit - 是否可以根据 map 类型更改 map 图钉?

android - 打开应用程序时是否可以删除白屏?

ios - 子类化 MKMapView 并使其成为 mapview 委托(delegate),同时仍然允许其他委托(delegate)

iphone - ios Mapkit : fix annotation on middle of map