Skip to main content
Version: 1.x

Custom Location Source

Drive the Wemap map, AR view and navigation from a location provider of your own, such as a BLE, UWB or Wi-Fi indoor positioning vendor, by implementing LocationSource.

How it works​

You implement three hooks, and the SDK calls them: onStart(listener), onStop() and onRelease(). The SDK starts and stops your source as the map and AR views need it. Each time it starts the source, it hands it a LocationSourceListener: report every update from your provider to that listener until the source is stopped.

What you report is processed exactly like the updates of Wemap's own sources. Each coordinate is projected on the navigation's itinerary, or on the map's graph, when projection is enabled, and then published on the session's coordinates stream, which the map's user location, the AR view and navigation all read.

Implementing a source​

class MyLocationSource(
override val coreSession: CoreSession,
private val provider: MyProvider
) : LocationSource {

private var listener: LocationSourceListener? = null

override fun onStart(listener: LocationSourceListener) {
this.listener = listener
provider.startUpdates(
onFix = { fix ->
val coordinate = Coordinate(
latitude = fix.latitude,
longitude = fix.longitude,
levels = Levels.Single(fix.floor),
horizontalAccuracy = fix.accuracyMeters
)
listener.onCoordinateChanged(coordinate)
},
onFailure = { error -> listener.onError(error) }
)
}

override fun onStop() {
provider.stopUpdates()
listener = null
}

override fun onRelease() {
provider.release()
}
}
  • coreSession is the session the source reports to. Create the source with the same session as the map or AR view it drives.
  • onStart(listener) is called by the SDK. The listener can be called from any thread. Every start gets a new listener, and the previous one stops forwarding: an update your provider delivers after the source was stopped or replaced is dropped.
  • onStop() is called by the SDK when the source stops: stop your provider's updates there.
  • isStarted is kept by the SDK. You don't implement it.
  • supportsAttitude is false by default, and the SDK then reads the device's attitude from its own sensors. Override it with true only if your provider reports the attitude, through onAttitudeChanged.
  • onError publishes the error on the session's errors stream.
  • onRelease() is called by the SDK once the source is stopped and removed from its session. Free your provider's resources there.

Attaching it​

Assign the source to the map or to the AR view, as any Wemap location source:

val source = MyLocationSource(session, provider)

mapView.userLocationManager.locationSource = source
// or
geoARView.locationManager.locationSource = source

To use the source without a Wemap view, start it yourself with start(), collect its coordinates, attitudes and errors, and stop it with stop(). These are extensions on LocationSource, imported from com.getwemap.sdk.core.location. A source you start yourself stays yours to stop.

Never call the on hooks yourself: start(), stop() and deinit() are what keep the SDK's view of the source right.

Releasing it​

When you no longer need the source, call deinit(), as for any Wemap location source:

override fun onDestroyView() {
super.onDestroyView()
source.deinit()
}

deinit() stops the source, removes it from the map and AR views of its session, then calls your onRelease(). Calling onRelease() yourself instead would leave the source installed on the session, to be started again by the next view that needs positioning.