Skip to content

🛰 Lightweight location positioning in Swift

License

Notifications You must be signed in to change notification settings

m-at-drigmo/Position

 
 

Repository files navigation

Position is a lightweight location positioning library for iOS.

Build Status Swift Package Manager Pod Version Swift Version GitHub license

Features
“one shot” customizable location requests
🌌 distance and time-based location filtering
🛰 location tracking support
🧭 device heading support
🔒 permission check and response support
🌐 geospatial math utilities
🏙 place data formatting utilities
📊 automatic low-battery location modes
📍 vCard location creation
🔭 multiple component observer-based architecture

Quick Start

Position is available for installation using the Swift Package Manager or the Cocoa dependency manager CocoaPods. Alternatively, you can simply copy the Position source files into your Xcode project.

# CocoaPods
pod "Position", "~> 0.7.0"

# Carthage
github "piemonte/Position" ~> 0.7.0

# SwiftPM
let package = Package(
    dependencies: [
        .Package(url: "https://github.com/piemonte/Position", majorVersion: 0)
    ]
)

Usage

The sample project provides an example of how to integrate Position, otherwise you can follow these steps.

Ensure your app’s Info.plist file includes both a location usage description, required device capability “location-services”, and required background mode (if necessary).

See sample project for examples.

Import the file and setup your component to be a PositionObserver, if you’d like it to be a delegate.

import Position

class ViewController: UIViewController, PositionObserver {
	// ...

Have the component add itself as an observer and configure the appropriate settings.

    override func viewDidLoad() {
        super.viewDidLoad()

        // ...

        Position.shared.addObserver(self)
        Position.shared.distanceFilter = 20

        if Position.shared.locationServicesStatus == .allowedWhenInUse ||
           Position.shared.locationServicesStatus == .allowedAlways {
            Position.shared.performOneShotLocationUpdate(withDesiredAccuracy: 250) { (location, error) -> () in
                print(location, error)
            }
        } else {
            // request permissions based on the type of location support required.
            Position.shared.requestWhenInUseLocationAuthorization()
            // Position.shared.requestAlwaysLocationAuthorization()
        }
    }

Observe delegation, if necessary.

    func position(position: Position, didChangeLocationAuthorizationStatus status: LocationAuthorizationStatus) {
        // location authorization did change, often this may even be triggered on application resume if the user updated settings
    }

Remember when creating location-based apps, respect the privacy of your users and be responsible for how you use their location. This is especially true if your application requires location permission kCLAuthorizationStatusAuthorizedAlways.

To share a location using a vCard, simply call the vCard function on any location object instance.

   let fileURL = location.vCard()

Core Location Additions

Position is bundled with a variety of additions to Core Location, such as geospatial math utilities. For example, one can calculation the direction between two coordinate points enabling directional views and other waypoint representations.

Documentation

You can find the docs here. Documentation is generated with jazzy and hosted on GitHub-Pages.

Community

Resources

License

Position is available under the MIT license, see the LICENSE file for more information.

About

🛰 Lightweight location positioning in Swift

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Swift 96.4%
  • Objective-C 2.2%
  • Other 1.4%