MapMatching
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, lon: 2.3522 },
{ lat: 48.8606, lon: 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()
staticclearItinerary():void
Clear the itinerary (disable map matching)
Returns
void
Example
MapMatching.clearItinerary();
getItinerary()
staticgetItinerary():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()
staticsetItinerary(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
The itinerary object from @wemap/routers, or null to disable map matching
Itinerary | null
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]);