Skip to content
This repository has been archived by the owner on Oct 15, 2021. It is now read-only.

futuredapp/LocationManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LocationManager

Version License Platform

Deprecation notice: The project is no longer under active development. Please seek other methods like PromiseKit/CoreLocation.

Usage

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

Installation

LocationManager is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod "LocationManager"

Example

Getting current location

import LocationManager
import PromiseKit

let desiredAccuracy: CLLocationAccuracy? = kCLLocationAccuracyBestForNavigation

LocationManager.sharedManager.getCurrentLocation(desiredAccuracy: desiredAccuracy).done { location in
    print("your current location: \(location)")
}.catch { error in
    print("error getting location: \(error)")
}

When using location observing, you can use these parameters:

  • desiredAccuracy: CLLocationAccuracy? - specifies desired accuracy (see CoreLocation documentations for more info)

Observing location

import LocationManager

class MyObserver: LocationObserver {
    func didUpdateLocation(manager: LocationManager, location: CLLocation) {
        print("your location changed \(location)")
    }
}

let desiredAccuracy: CLLocationAccuracy? = kCLLocationAccuracyBestForNavigation
let distanceFilter: CLLocationDistance? = 50 // meters
let observer = MyObserver()

LocationManager.sharedManager.addLocationObserver(observer, desiredAccuracy: desiredAccuracy, distanceFilter: distanceFilter)

When using location observing, you can use these parameters:

  • desiredAccuracy: CLLocationAccuracy? - specifies desired accuracy (see CoreLocation documentations for more info)
  • distanceFilter: CLLocationDistance? - filter distances (desired distance between new location and previous location)
  • minimumTimeInterval: TimeInterval? - specifies how often should location update method be called (minimum interval between calls - max frequency)
  • maximumTimeInterval: TimeInterval? - forces location update calls event even if there's no new location available (maximum interval between calls)

Distance Filter and Desired Accuracy

LocationManager efficiently uses filter and accuracy of all requests and observers and calculates maximum required values to prevent battery draining.

For example if you have two observers with 50 m and 100 m distance filter, the overall distance filter would be 50 m. When you remove the observer with 50 m filter, the overall distance filter is recalculated to maximum required value (which is 100 m). The same applies to desiredAccuracy.

License

LocationManager is available under the MIT license. See the LICENSE file for more info.