Swiftpack.co -  piemonte/Position as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
piemonte/Position
🛰 Lightweight and efficient location positioning in Swift
.package(url: "https://github.com/piemonte/Position.git", from: "0.8.3")

Position is a lightweight and efficient location positioning library for iOS.

Build Status Pod Version Swift Version GitHub license

Features
“one shot” customizable location requests
🌌 distance and time-based location filtering
🛰 location tracking support
📊 automatically manage energy resources based on tracking
🔒 permission check and response support
📍 vCard location creation
🌁 automatic low-power location tracking adjustment when backgrounded setting
🔋 automatic low-power location tracking adjustment from battery monitoring setting
🔭 multiple component observer-based architecture

Need a different version of Swift?

  • 5.0 - Target your Podfile to the latest release or master
  • 4.2 - Target your Podfile to the swift4.2 branch

Quick Start

Position is available for installation using 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 too.

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()

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.

GitHub

link
Stars: 59
Last commit: 3 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API