适用于 iOS 的位置、运动和活动记录框架

定位套件

适用于 iOS 的基于机器学习的位置记录和活动检测框架。

位置和运动记录

  • 组合、简化的核心位置和核心运动记录
  • 经过过滤、平滑和简化的位置和运动数据
  • 近乎实时的静止/移动状态检测
  • 自动能源使用管理,支持全天记录
  • 自动停止和重新启动录制,避免浪费电池使用

活动类型检测

  • 基于机器学习的活动类型检测
  • 改进了对核心运动活动类型(静止、步行、跑步、骑行、
    汽车)的检测
  • 区分特定的运输类型(汽车、火车、公共汽车、摩托车、飞机、轮船)

记录高级别访问和路径

  • (可选)生成高级和时间线项目,以在人类级别表示录制
    会话。与核心位置类似,但具有更高的准确性,
    更多的细节,并增加了路径(即访问之间的行程)。
    PathVisitCLVisit
  • (可选)将录制的示例和时间线项目保存到基于 SQL 的本地存储中,以便在
    会话之间保留。

有关时间线项目的更多信息,请参阅此处

支持项目

LocoKit 是一个 LGPL 许可的开源项目。它的持续发展得益于
其支持者对 Patreon 的支持。

如果您的应用程序使用 LocoKit 并且是创收产品,请考虑
赞助 LocoKit 开发,以确保您的产品所依赖的项目保持
健康并得到积极维护。

非常感谢您的支持!

安装

pod 'LocoKit'
pod 'LocoKit/LocalStore' # optional
Ruby

Note: Include the optional subspec if you would like to retain your samples
and timeline items in the SQL persistent store.
LocoKit/LocalStore

High Level Recording

Record TimelineItems (Paths and Visits)

// retain a timeline manager
self.timeline = TimelineManager()

// start recording, and producing timeline items 
self.timeline.startRecording()

// observe timeline item updates
when(timeline, does: .updatedTimelineItem) { _ in
    let currentItem = timeline.currentItem

    // duration of the current Path or Visit
    print("item.duration: \(currentItem.duration)")

    // activity type of the current Path (eg walking, cycling, car)
    if let path = currentItem as? Path {
        print("path.activityType: \(path.activityType)")
    }

    // examine each of the LocomotionSamples within the Path or Visit
    for sample in currentItem.samples {
        print("sample: \(sample)")
    }
}
Swift

Low Level Recording

Record LocomotionSamples (CLLocations combined with Core Motion data)

// the recording manager singleton
let loco = LocomotionManager.highlander
Swift
// decide which Core Motion features to include
loco.recordPedometerEvents = true
loco.recordAccelerometerEvents = true
loco.recordCoreMotionActivityTypeEvents = true
Swift
// decide whether to use "sleep mode" to allow for all day recording 
loco.useLowPowerSleepModeWhileStationary = true
Swift

Note: The above settings are all on by default. The above snippets are unnecessary, and just here
to show you some of the available options.

// start recording 
loco.startRecording()
Swift
// watch for updated LocomotionSamples
when(loco, does: .locomotionSampleUpdated) { _ in

    // the raw CLLocation
    print(loco.rawLocation)

    // a more usable, de-noised CLLocation
    print(loco.filteredLocation)

    // a smoothed, simplified, combined location and motion sample
    print(loco.locomotionSample())
}
Swift

Fetching TimelineItems / Samples

If you wanted to get all timeline items between the start of today and now, you might do this:

let date = Date() // some specific day
let items = store.items(
        where: "deleted = 0 AND endDate > ? AND startDate < ? ORDER BY endDate",
        arguments: [date.startOfDay, date.endOfDay])
Swift

You can also construct more complex queries, like for fetching all timeline items that overlap a certain geographic region. Or all samples of a specific activity type (eg all "car" samples). Or all timeline items that contain samples over a certain speed (eg paths containing fast driving).

Detect Activity Types

Note that if you are using a , activity type classifying is already handled
for you by the manager, on both the sample and timeline item levels. You should only need to
directly interact with clasifiers if you are either not using a TimelineManager, or are wanting
to do low level processing at the sample level.
TimelineManager

// fetch a geographically relevant classifier
let classifier = ActivityTypeClassifier(coordinate: location.coordinate)

// classify a locomotion sample
let results = classifier.classify(sample)

// get the best match activity type
let bestMatch = results.first

// print the best match type's name ("walking", "car", etc)
print(bestMatch.name)
Swift

Note: The above code snippets use SwiftNotes to make
the event observing code easier to read. If you're not using SwiftNotes, your observers should be
written something like this:

let noteCenter = NotificationCenter.default
let queue = OperationQueue.main 

// watch for updates
noteCenter.addObserver(forName: .locomotionSampleUpdated, object: loco, queue: queue) { _ in
    // do stuff
}
Swift

Background Location Monitoring

If you want the app to be relaunched after the user force quits, enable significant location change monitoring.

More details and requirements here

Examples and Screenshots

Documentation

Try the LocoKit Demo App

  1. Download or clone this repository
  2. pod install
  3. In Xcode, change the Demo App project's "Team" to match your Apple Developer Account
  4. In Xcode, change the Demo App project's "Bundle Identifier" to something unique
  5. Build and run!
  6. Go for a walk, cycle, drive, etc, and see the results :)

Try Arc App on the App Store

  • To see the SDK in action in a live, production app, install
    Arc App
    from the App Store, our free life logging app based on LocoKit

GitHub

https://github.com/sobri909/LocoKit