gpt4 book ai didi

ios - 使用 CLLocation 计算距离 iOS MapKit

转载 作者:可可西里 更新时间:2023-11-01 05:16:08 24 4
gpt4 key购买 nike

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

- (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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com