ILocationSource
Interface: ILocationSource
Base interface for all position data sources
Each location source implements this interface and emits pose updates. Location sources can be started/stopped and provide callbacks for updates and errors.
Example
const locationSource: ILocationSource = new VPSLocationSource();
locationSource.onUpdate((pose) => {
console.log('Position:', pose.position);
});
locationSource.onError((error) => {
console.error('Location error:', error);
});
await locationSource.start();
Methods
offError()?
optionaloffError(callback):void
Remove the error callback
Parameters
callback
(error) => void
The callback function to remove
Returns
void
Example
const errorHandler = (error) => { };
locationSource.onError?.(errorHandler);
// Later...
locationSource.offError?.(errorHandler);
offUpdate()?
optionaloffUpdate(callback):void
Remove the update callback
Parameters
callback
(data) => void
The callback function to remove
Returns
void
Example
const updateHandler = (pose) => { };
locationSource.onUpdate(updateHandler);
// Later...
locationSource.offUpdate?.(updateHandler);
onError()?
optionalonError(callback):void
Register a callback to receive error events
Parameters
callback
(error) => void
Function to call when an error occurs
Returns
void
Example
locationSource.onError((error) => {
console.error('Location source error:', error.message);
});
onUpdate()
onUpdate(
callback):void
Register a callback to receive pose updates
The callback receives pose data whenever the location source provides an update. Multiple callbacks can be registered.
Parameters
callback
(data) => void
Function to call when pose data is updated
Returns
void
Example
locationSource.onUpdate((pose) => {
if (pose.position) {
console.log(`Lat: ${pose.position.lat}, Lon: ${pose.position.lon}`);
}
});
start()
start():
Promise\<void>
Start the location source and begin emitting updates
Returns
Promise\<void>
Throws
If the location source cannot be started
Example
await locationSource.start();
stop()
stop():
Promise\<void>
Stop the location source and stop emitting updates
Returns
Promise\<void>
Example
await locationSource.stop();