THIS SDK ISDEPRECATED.

We rolled out a new and better SDK for you.

Map and route matching

Map matching snaps an inaccurate GPS probe to the road network obtained from map tiles so roads are represented by collections of coordinates. Route matching is a special case of map matching which snaps an inaccurate GPS probe to the given route. The reference route is represented by a collection of coordinates. The route can be calculated using the Routing API or provided manually.

Sample use case: You have a speed radar application that is used when driving. To have a proper user experience, you want to match GPS positions with the road data obtained from map tiles.

Sample use case: You want to match/place the chevron with the right road.

Sample use case: A user plans and displays a route on the map in your app. The vehicle position is being matched along the planned route.

First you need to create a proper MatchingDataProvider based on your use case.

To create the MatchingDataProvider from a route:

MatchingDataProvider routeMatchingProvider = LatLngTraceMatchingDataProvider.fromPoints(getFirstRouteFromMap())
val routeMatchingProvider = LatLngTraceMatchingDataProvider.fromPoints(routes.first().getCoordinates())

To create the MatchingDataProvider for map matcher:

MatchingDataProvider matchingDataProvider = tomtomMap.asMatchingDataProvider();
return tomtomMap.asMatchingDataProvider()

After you obtain the MatchingDataProvider, you can create and register matcher in the following manner:

matcher = MatcherFactory.createMatcher(matchingDataProvider);
matcher.setMatcherListener(matcherListener);
val matcher = MatcherFactory.createMatcher(matchingDataProvider)
matcher.setMatcherListener(this)

It is important to remove the matcher instance if it is not going to be used. Otherwise memory leaks may occur:

matcher.dispose();
matcher.dispose()

To update map matcher with a new GPS position:

matcher.match(location);
matcher.match(location)

To process map matcher results:

1@Override
2public void onMatched(MatchResult matchResult) {
3 ChevronPosition chevronPosition = new ChevronPosition.Builder(matchResult.getMatchedLocation()).build();
4
5 chevron.setDimmed(!matchResult.isMatched());
6 chevron.setPosition(chevronPosition);
7 chevron.show();
8
9 tomtomMap.getOverlaySettings().removeOverlays();
10 tomtomMap.getOverlaySettings().addOverlay(
11 CircleBuilder.create()
12 .position(new LatLng(matchResult.originalLocation))
13 .fill(GPS_DOT_FILL)
14 .color(GPS_DOT_COLOR)
15 .radius(GPS_DOT_RADIUS)
16 .build()
17 );
18}
1val chevronPosition = ChevronPosition.Builder(it.matchedLocation).build()
2chevron.isDimmed = it.isDimmed
3chevron.position = chevronPosition
4chevron.show()
5showOriginalLocationDot(it)