- Notifications
You must be signed in to change notification settings - Fork9
🛰 Lightweight location positioning in Swift
License
piemonte/Position
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Position
is a lightweight location positioning library for iOS.
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 |
Position
is available for installation using theSwift Package Manager or the Cocoa dependency managerCocoaPods. Alternatively, you can simply copy thePosition
source files into your Xcode project.
# CocoaPodspod"Position","~> 0.7.0"# Carthagegithub"piemonte/Position" ~>0.7.0# SwiftPMletpackage=Package(dependencies:[.Package(url:"https://github.com/piemonte/Position",majorVersion:0)])
The sample project provides an example of how to integratePosition
, otherwise you can follow these steps.
Ensure your app’sInfo.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 PositionclassViewController:UIViewController,PositionObserver{// ...
Have the component add itself as an observer and configure the appropriate settings.
overridefunc viewDidLoad(){ super.viewDidLoad() // ...Position.shared.addObserver(self)Position.shared.distanceFilter=20ifPosition.shared.locationServicesStatus==.allowedWhenInUse ||Position.shared.locationServicesStatus==.allowedAlways{Position.shared.performOneShotLocationUpdate(withDesiredAccuracy:250){(location, error)->()inprint(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 permissionkCLAuthorizationStatusAuthorizedAlways
.
To share a location using a vCard, simply call the vCard function on any location object instance.
letfileURL= location.vCard()
Position is bundled with a variety ofadditions to Core Location, such as geospatial math utilities. For example, one can calculation the direction between two coordinate points enablingdirectional views and other waypoint representations.
You can findthe docs here. Documentation is generated withjazzy and hosted onGitHub-Pages.
- Need help? UseStack Overflow with the tag ‘position-swift’.
- Questions? UseStack Overflow with the tag ‘position-swift’.
- Found a bug? Open anissue.
- Feature idea? Open anissue.
- Want to contribute? Submit apull request.
Position is available under the MIT license, see theLICENSE file for more information.
About
🛰 Lightweight location positioning in Swift