Installation
Before you start developing your application with WemapSDKs, you need to configure your credentials and add the SDK as a dependency.
The code examples below demonstrate how to configure the
WemapPositioningSDK
to work with theWemapMapSDK
, but it can also be used independently. Instructions are here
Adding the Dependency
To add WemapSDKs to your app:
Add Dependencies in the
Podfile
Add the required WemapSDK pods to your app:
use_frameworks! target 'TargetNameOfYourApp' do # Add the dependency for the WemapMapSDK library pod 'WemapMapSDK', '<version>' # Add the dependency for the WemapPositioningSDK library pod 'WemapPositioningSDKPolestar', '<version>' # Polestar Location Source pod 'WemapPositioningSDK/VPSARKit', '<version>' # Wemap VPS ARKit Location Source end
Ensure Minimum iOS Version
Your project must target iOS 12.0 or later:
platform :ios, '12.0'
Install Dependencies and Open the Project
Run the following command to install the pods:
AWS_ACCESS_KEY_ID=*** \ AWS_SECRET_ACCESS_KEY=*** \ AWS_REGION=*** \ bundle exec pod install --repo-update
Then, open your project in Xcode:
open your-project.xcworkspace
Location Sources
Wemap provides a variety of location sources to manage the user’s location on the map. By default, WemapMapSDK
uses Apple’s LocationProvider
to obtain raw location updates.
To set a specific location source, you need to:
Add the relevant
WemapPositioningSDK
library to your project dependencies.Assign the location source to the map.
If you want the camera to follow the user’s direction, you can do so by changing the
userTrackingMode
of the map, as shown below:map.userTrackingMode = .followWithHeading
Polestar location source
func setupLocationSource() {
let source = PolestarLocationSource(apiKey: "emulator")
map.userLocationManager.locationSource = source
}
Wemap VPS ARKit location source
To use the VPS Location Source, you must have a mapID
and token
or a VPS serviceURL
. For more details, please contact Wemap team.
Fetching the VPS Service URL
WemapMap.shared
.getMapData(mapID: 19158, token: "GUHTU6TYAWWQHUSR5Z5JZNMXX")
.subscribe(onSuccess: { [self] mapData in
// mapData contains the VPS service URL
}, onFailure: {
debugPrint("Failed to get map data with error - \($0)")
})
.disposed(by: disposeBag)
Setting Up the VPS ARKit Location Source
Once you have the serviceURL
, create a VPSARKitLocationSource
instance:
func setupLocationSource() {
vpsLocationSource = VPSARKitLocationSource(serviceURL: mapData?.extras?.vpsEndpoint ?? "https://your-wemap-vps-endpoint")
vpsLocationSource.vpsDelegate = self
map.userLocationManager.locationSource = source
}
Handling Location Source State Changes
You must handle state changes in VPSARKitLocationSourceDelegate
, as users may need to scan their environment.
extension ViewController: VPSARKitLocationSourceDelegate {
func locationSource(_ locationSource: VPSARKitLocationSource, didChangeState state: VPSARKitLocationSource.State) {
// Handle state changes
}
func locationSource(_ locationSource: VPSARKitLocationSource, didChangeScanStatus status: VPSARKitLocationSource.ScanStatus) {
// Handle scan status changes
}
func locationSource(_ locationSource: VPSARKitLocationSource, didFailWithError error: VPSARKitLocationSourceError) {
// Handle location source errors
}
}
Scanning the Environment
To start tracking the user’s location, you need to allow the user to scan their environment:
func startScan() {
vpsLocationSource.startScan()
}
Once the system successfully recognizes the user’s location, it will report the accuratePositioning
state to VPSARKitLocationSourceDelegate
. Shortly after, VPS system will start updating user’s location indicator on the map.
Important note
Starting from iOS 18, there is a bug where
ARSession
is automatically stopped byARView
when the view is dismissed or hidden. As a result, the positioning process stops after a few seconds. If you are usingARView
, we recommend a workaround in our sample application
Examples
For additional examples and sample implementations of WemapSDKs, visit the official GitHub repository.
Clone the repository and follow the README instructions to run the sample application.