Skip to main content

GPS Location Source

The Global Positioning System (GPS) is a satellite-based hyperbolic navigation system.

Requirements

Check common requirement.

Installation

Check common installation.

Permissions

GPS Location Source requires GPS permission. Declare NSLocationWhenInUseUsageDescription in your app Info.plist as follows:

<key>NSLocationWhenInUseUsageDescription</key>
<string>Used to track user location</string>

Please request location permission before creating and starting GPSLocationSource, because without access to it - system can't work. If you don't do it, system will request permission on first access to location.

func requestLocationPermission() {
// show a model explaining that location access is crucial for localization and navigation.
// then request for location permission
let locationManager = CLLocationManager()
locationManager.requestWhenInUseAuthorization()
}

func checkLocationPermission() {
let status = CLLocationManager.authorizationStatus()
switch status {
case .authorizedWhenInUse, .authorizedAlways:
// User granted access. GPS Location Source can be created and started
case .denied, .restricted:
// User denied access. Show a message explaining how to enable it in settings
case .notDetermined:
requestLocationPermission()
@unknown default:
break
}
}

Setting Up the GPS Location Source

Once you have the MapData, create a GPSLocationSource instance, then assign it to Map or/and GeoAR as follows:

func setupLocationSource(mapData: MapData) {
let gpsLocationSource = GPSLocationSource(mapData: mapData)

// assign it to the map if you are using WemapMapSDK
map.userLocationManager.locationSource = gpsLocationSource

// or/and assign it to GeoARView if you are using WemapGeoARSDK
geoARView.locationManager.locationSource = gpsLocationSource
}

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.