iOS:24/7 全天候跟踪用户移动

标签 ios location cllocationmanager

我需要跟踪用户何时旅行。为此,我像这样设置 CLLocationManager:

self.locationManager.requestAlwaysAuthorization()
self.locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters
self.locationManager.distanceFilter = 200                       
self.locationManager.pausesLocationUpdatesAutomatically = false                      
self.locationManager.allowsBackgroundLocationUpdates = true
self.locationManager.activityType = .other

所以即使我的应用程序没有运行,它也会获取位置,将位置保存在数据库中并再次进入后台。稍后当用户启动应用程序时,将从数据库中的新位置提取旅行。

这或多或少会消耗约 15% 的能量。该位置是在手机信号塔的帮助下确定的,而不是通过 GPS 确定的。

我意识到在某些日子里,跟踪对某些地区(火车轨道)不起作用。您知道为什么会发生这种情况吗? (仅限 iOS10 设备)。

您认为实现我的目标有改进吗?还有什么可以用来确定旅行的吗? (旅行是指您以超过 15 公里/小时和超过 15 分钟的速度通勤)。

谢谢

最佳答案

可以有多种事件类型,可以帮助您定位轨道、船只等。以下是有关事件类型的苹果文档:

public enum CLActivityType : Int {


    case other

    case automotiveNavigation // for automotive navigation

    case fitness // includes any pedestrian activities

    case otherNavigation // for other navigation cases (excluding pedestrian navigation), e.g. navigation for boats, trains, or planes
}

您可以使用self.locationManager.activityType = .otherNavigation

关于iOS:24/7 全天候跟踪用户移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42548761/

相关文章:

mongodb - postgresql 或 Mongodb 用于存储位置数据(纬度和经度)并基于以下内容进行搜索?

android - 仅在android中使用wifi获取当前位置

javascript - 设置 top.location 并打开新选项卡?

ios - requestLocation() 在使用 Swift 2 的模拟器中总是失败

Swift CLAuthorizationStatus 总是 CLAuthorizationStatus.NotDetermined

ios - NativeScript 静态库实现如何生成 TypeScript 声明

ios - 对 Apple 的 Block Docs 的澄清?

ios - 如何将单个 TableView 单元链接到另一个 ViewController

iphone - 为什么在iOS4.0中没有调用CurrentLotion(CLLocationManager)的委托(delegate)方法?

iphone - NSDateFormatter IOS 错误