This Swift Package is an example of a Position Provider for MapsIndoors that can take a number of other Position Providers and return the "best" result available. "Best" is in this example the position with the lowest accuracy.
- iOS 15.0 or later
- Xcode 16 or later
- MapsIndoors iOS SDK (using either Mapbox Maps or Google Maps
- A MapsIndoors API key
- In Xcode, open your project.
- Go to
File
->Add Package Dependencies…
- Enter the repository URL for this package (https://github.com/MapsPeople/mapsindoors-switchingprovider-ios.git)
- Follow the prompts to select the package and target for installation.
Add the following to your Package.swift
file:
dependencies: [
.package(url: "https://github.com/MapsPeople/mapsindoors-switchingprovider-ios.git", .upToNextMajor(from: "1.0.0")),
]
If you prefer more control, want to understand how it works, or want to customize the position provider package, you can fork this repository. By forking the repository, you create your own copy of the project, which you can modify to suit your specific requirements while retaining the base functionality.
- Fork the repository to your own GitHub account.
- Clone the forked repository to your local machine.
- Add the forked repository as a dependency in your
Package.swift
file:
dependencies: [
.package(url: "https://github.com/YOUR_USERNAME/mapsindoors-switchingprovider-ios.git", .upToNextMajor(from: "1.0.0")),
]
The position provider should only be initialized when user positioning is required. It depends on MapsIndoors being initialized.
- Obtain the necessary API keys and credentials for MapsIndoors.
- Get MapsIndoors API key from the MapsIndoors CMS, or contact MapsPeople.
Follow the instructions for requesting permissions for each individual Position Provider.
// Import the MapsIndoors SDK
import MapsIndoors
// Import the Switching Position Provider for MapsIndoors
import SwitchingPositionProvider
// Initialize the Switching PositionProvider.
let switchingPositionProvider = SwitchingPositionProvider()
// Add position providers to select "best" result from
let switchingPositionProvider = SwitchingPositionProvider()
let crowdConnectedPositionProvider = CrowdConnectedPositionProvider(appKey: "YOUR_CROWDCONNECTED_APP_KEY", token: "YOUR_CROWDCONNECTED_TOKEN", secret: "YOUR_CROWDCONNECTED_SECRET")
switchingPositionProvider.addPositionProvider(crowdConnectedPositionProvider)
// Use the Switching Position Provider in MapsIndoors.
MPMapsIndoors.shared.positionProvider = switchingPositionProvider
mapControl?.showUserPosition = true