All Projects → andyshep → Waypoints

andyshep / Waypoints

Licence: mit
Easy location tracking in Swift

Programming Languages

swift
15916 projects

#Waypoints

Easy location tracking in Swift.

  • Add multiple observers for a single location change.
  • Configure the minimum distance before a new location is published.
  • Supports reverse geocoding.
  • Target iOS or macOS.

##Usage

Create a LocationTracker instance with the default minimum distance threshold of zero meters:

let locationTracker = LocationTracker()

Create a LocationTracker with a minimum distance threshold of 50 meters:

let locationTracker = LocationTracker(threshold: 50.0)

Add a location change observer to an existing LocationTracker instance:

locationTracker.addLocationChangeObserver { (result) -> () in
    switch result {
    case .success(let location):
        // handle new location
    case .failure(let reason):
        // handle failure
    }
}

The location is returned as a LocationResult type, representing either the Location or an Error about why the location could not be obtained.

public enum LocationResult {
    case success(Location)
    case failure(Error)
}

The Location type combines a CLLocation with metadata for the associated city, state, and neighborhood. Address information is obtained using CLGeocoder.

public struct Location {
    let physical: CLLocation
    let city: String
    let state: String
    let neighborhood: String
}

See the Example project for iOS and OS X demos.

##Requirements

  • Xcode 8
  • Swift 3

##Installation

Clone the repo directly and copy LocationTracker.swift into your Xcode project.

##Configuration

Starting in iOS 8, the privacy settings require you to specify why the location is needed before the app is authorized to use it. Add an entry into the Info.plist for NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription.

If location is only required when app is active.

<key>NSLocationWhenInUseUsageDescription</key>
<string>Location required because...</string>

If the location is always required.

<key>NSLocationAlwaysUsageDescription</key>
<string>Location always required because...</string>

License

The MIT License

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].