Routing
The routing module allows you to generate safe and legal routes for commercial vehicles and display those routes on the map. The code samples below depict how to build a simple route with two stops.
Retrieve the route plugin module:
const TrimbleMapsRoute = NativeModules.TrimbleMapsRouteModule;
Before adding a route to the map, ensure that the map has loaded.
const createRoute = async () => {
let stops = [
[40.361202, -74.599773],
[40.232968, -74.773348],
];
if (Platform.OS === "ios") {
// initialize route options with stops of the trip
await TrimbleMapsRoute.createRouteOptions(stops);
await TrimbleMapsRoute.color(TrimbleMapsMapViewConstants.MAGENTA);
// generate route takes id of the route
await TrimbleMapsRoute.generateRoute("testRoute");
} else if (Platform.OS === "android") {
await TrimbleMapsRoute.createDirectionsBuilder();
await TrimbleMapsRoute.origin(40.361202, -74.599773);
await TrimbleMapsRoute.destination(40.232968, -74.773348);
await TrimbleMapsRoute.buildDirections();
await TrimbleMapsRoute.createRouteBuilder();
await TrimbleMapsRoute.id("testRoute");
await TrimbleMapsRoute.routeOptions();
await TrimbleMapsRoute.color(TrimbleMapsMapViewConstants.MAGENTA);
await TrimbleMapsRoute.buildRoute();
}
// adds the route to the current map view
await TrimbleMapsRoute.addRoute();
// moves the map camera to the route
await TrimbleMapsRoute.frameRoute();
};