Skip to main content

ILocationSource

wemap-sdk-js


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​

dispose()?​

optional dispose(): Promise<void>

Permanently tear down the location source and release all resources.

Stops the source and clears every registered callback. After dispose() the instance should be discarded and not restarted.

Returns​

Promise<void>

Example​

await locationSource.dispose?.();

offError()?​

optional offError(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()?​

optional offUpdate(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()?​

optional onError(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}, Lng: ${pose.position.lng}`);
}
});

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();