Skip to main content

Calculate Bike Route

|

Calculate routes optimized for bicycle navigation with cycling-specific preferences.

Live Demo

Code Implementation

index.ts
function onBuildRouteButtonPressed() {
const departureLandmark = Landmark.withLatLng({
latitude: 52.36239785,
longitude: 4.89891628
});

const destinationLandmark = Landmark.withLatLng({
latitude: 52.3769534,
longitude: 4.898427
});

const routePreferences = new RoutePreferences({
bikeProfile: new BikeProfileElectricBikeProfile({
profile: selectedBikeType || BikeProfile.city
})
});

showMessage('The bike route is calculating.');

RoutingService.calculateRoute(
[departureLandmark, destinationLandmark],
routePreferences,
(err: GemError, calculatedRoutes: Route[]) => {
routingHandler = null;

if (err === GemError.success) {
const routesMap = map?.preferences.routes;

calculatedRoutes.forEach((route, index) => {
const label = getRouteLabel(route);
routesMap?.add(route, index === 0, { label });
});

map?.centerOnRoutes({ routes: calculatedRoutes });
showMessage('Bike route calculated successfully!');

routes = calculatedRoutes;
} else {
showMessage('Bike route calculation failed.');
}
}
);
}

updateUI();

updateUI();