Skip to main content

MapMatching

wemap-sdk-js


Class: MapMatching

Map Matching utility for projecting user position onto an itinerary

Map matching projects GPS positions onto a predefined route/itinerary, providing more accurate navigation by constraining positions to the route. This is especially useful for indoor navigation where GPS accuracy may be limited.

When an itinerary is set, location sources will automatically project position updates onto the route, ensuring the user's position stays aligned with the planned path.

Example​

import { MapMatching } from '@wemap/positioning';
import { Router } from '@wemap/routing';

// Create a router instance and calculate a route
const router = new Router();
const itineraries = await router.directions(
{ lat: 48.8566, lng: 2.3522 },
{ lat: 48.8606, lng: 2.3376 },
'WALK'
);

// Set the first itinerary for map matching
MapMatching.setItinerary(itineraries[0]);

// Later, to clear it:
MapMatching.clearItinerary();

Constructors​

Constructor​

new MapMatching(): MapMatching

Returns​

MapMatching

Methods​

clearItinerary()​

static clearItinerary(): void

Clear the itinerary (disable map matching)

Returns​

void

Example​

MapMatching.clearItinerary();

getItinerary()​

static getItinerary(): Itinerary | null

Get the current itinerary used for map matching

Returns the currently active itinerary, or null if map matching is disabled.

Returns​

Itinerary | null

The current itinerary or null if none is set

Example​

const currentItinerary = MapMatching.getItinerary();
if (currentItinerary) {
console.log('Map matching is active');
console.log('Route has', currentItinerary.legs.length, 'legs');
}

setItinerary()​

static setItinerary(itinerary): void

Set the itinerary for map matching

Sets the route/itinerary that will be used for map matching. All location sources will project their position updates onto this route.

Pass null to disable map matching.

Parameters​

itinerary​

Itinerary | null

The itinerary object from @wemap/routers, or null to disable map matching

Returns​

void

Example​

import { MapMatching } from '@wemap/positioning';
import { Router } from '@wemap/routing';

const router = new Router();
const itineraries = await router.directions(origin, destination, 'WALK');
MapMatching.setItinerary(itineraries[0]);