DesiredAcuracy 和 DistanceFilter 在 CoreLocation 中的作用是什么,ios

What is the role of DesiredAcuracy and DistanceFilter in CoreLocation, ios

我正在选择用户在 ios 项目中从 CoreLocation 步行时的 GPS 坐标,我想选择每 1 米或每 10 秒的纬度和经度,

我可以使用 DesiredAcuracy 和 DistanceFilter 这样做吗?

如果不是这两个(DesiredAcuracy 和 DistanceFilter)实际上会做什么?

或者我应该创建自己的计时器来完成它吗?

您必须使用 Core Location Framework。所以不要忘记添加和导入核心位置框架。

#import <CoreLocation/CoreLocation.h>

CLLocation *locA = [[CLLocation alloc] initWithLatitude:lat1 longitude:long1];

CLLocation *locB = [[CLLocation alloc] initWithLatitude:lat2 longitude:long2];

CLLocationDistance distance = [locA distanceFromLocation:locB];

//Distance in Meters
//1 meter == 100 centimeter
//1 meter == 3.280 feet
//1 square meter == 10.76 square feet

我可以使用 DesiredAcuracy 和 DistanceFilter 这样做吗? 是的,根据 docs:

所需精度

The receiver does its best to achieve the requested accuracy; however, the actual accuracy is not guaranteed.

You should assign a value to this property that is appropriate for your usage scenario. For example, if you need the current location only within a kilometer, you should specify kCLLocationAccuracyKilometer and not kCLLocationAccuracyBestForNavigation. Determining a location with greater accuracy requires more time and more power.

在您的情况下,您应该对未插入的设备使用 kCLLocationAccuracyKilometer(例如,用户将其用于 运行 距离)或对插入的设备使用 kCLLocationAccuracyBestForNavigation(例如,在车里)

kCLLocationAccuracyBestForNavigation

Use the highest possible accuracy and combine it with additional sensor data. This level of accuracy is intended for use in navigation applications that require precise position information at all times and are intended to be used only while the device is plugged in.

kCLLocationAccuracyKilometer

Accurate to the nearest kilometer. Available in iOS 2.0 and later.

kCLLocationAccuracyBest

Use the highest-level of accuracy. Available in iOS 2.0 and later.

距离过滤器

This distance is measured relative to the previously delivered location. >Use the value kCLDistanceFilterNone to be notified of all movements. The default value of this property is kCLDistanceFilterNone.

因此,如果您需要频繁的距离更新(即用户必须移动多远才能收到更新),您应该使用kCLDistanceFilterNone