GeoAR+PositioningSDK - Getting started
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 the WemapGeoARSDK
, but it can also be used independently. Instructions are available 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 WemapGeoARSDK library
pod 'WemapGeoARSDK', '<version>'
# Add the dependency for the WemapPositioningSDK library
pod 'WemapPositioningSDK/VPSARKit', '<version>' # Wemap VPS ARKit Location Source
pod 'WemapPositioningSDK/GPS', '<version>' # GPS Location Source
endEnsure minimum iOS version
Your project must target iOS 13.0 or later:
platform :ios, '13.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-updateThen, open your project in Xcode:
open your-project.xcworkspace
Add a GeoARView
Open the view controller where you want to add a GeoARView
and use the code below.
To make it work, you need to provide a mapID
and token
in the mapData
request.
import RxSwift
import UIKit
import WemapGeoARSDK
import WemapCoreSDK
class ViewController: UIViewController {
private var geoARView: GeoARView!
private let disposeBag = DisposeBag()
override func viewDidLoad() {
super.viewDidLoad()
ServiceFactory
.getMapService()
.map(byID: 22418, token: "GUHTU6TYAWWQHUSR5Z5JZNMXX")
.observe(on: MainScheduler.asyncInstance)
.subscribe(onSuccess: { [self] mapData in
geoARView = GeoARView(frame: view.bounds)
geoARView.viewDelegate = self
geoARView.mapData = mapData
view.addSubview(geoARView)
}, onFailure: {
debugPrint("Failed to get map data with error - \($0)")
})
.disposed(by: disposeBag)
}
}
extension ViewController: GeoARViewDelegate {
func geoARViewLoaded(_ arView: GeoARView, mapData: MapData) {
// setup location source. examples below
}
}
Location Sources
Wemap provides various location sources to track the user's location. There is no default Location Source embedded into WemapGeoARSDK
, so you have to choose one.
To use any location source, you must have a mapID
and token
. For more details, please contact the Wemap team.
To set a specific location source, you need to:
- Add the relevant
WemapPositioningSDK
library to your project dependencies. - Fetch
MapData
using yourmapID
andtoken
. - Create a
LocationSource
usingMapData
. - Assign the location source to
GeoARView
. Examples are given below.
Wemap VPS ARKit location source
Setting Up the VPS ARKit Location Source
Once you have the MapData
, create a VPSARKitLocationSource
instance, set vpsDelegate
, and assign it to the GeoARView
:
func setupLocationSource(mapData: MapData) {
vpsLocationSource = VPSARKitLocationSource(mapData: mapData)
vpsLocationSource.vpsDelegate = self
geoARView.locationManager.locationSource = vpsLocationSource
}
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
}
}
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 afterward, the VPS system will start updating the user’s camera location and orientation.
The VPS system will also report:
notPositioning
– indicates that the system hasn't yet recognized the environment and a VPS scan is required. At this point, you should present the camera view to the user to allow them to scan usingvpsLocationSource.startScan()
.degradedPositioning
– indicates that user location tracking is limited for various reasons (see reasons in API reference documentation). A scan is recommended, but not mandatory, to restore theaccuratePositioning
state. We recommend a small impact in the UI when this state occurs (location icon warning or a small toast message to suggest a rescan).
GPS Location Source
Once you have the MapData
, create a GPSLocationSource
instance and assign it to GeoARView
.
Setting Up the GPS Location Source
func setupLocationSource(mapData: MapData) {
let source = GPSLocationSource(mapData: mapData)
geoARView.locationManager.locationSource = source
}
The full example is available in our GitHub repository.
Itinerary generation
To know how to compute itineraries and start navigation check this doc
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.