Package com.cercalia.sdk.services
Class RoutingService
java.lang.Object
com.cercalia.sdk.CercaliaClient
com.cercalia.sdk.services.RoutingService
Service for route calculation using the Cercalia API.
RoutingService service = new RoutingService(config);
Coordinate origin = new Coordinate(41.3851, 2.1734);
Coordinate destination = new Coordinate(40.4168, -3.7038);
// 1. Basic route calculation
RouteResult result = service.calculateRoute(origin, destination, RoutingOptions.builder()
.avoidTolls(true)
.vehicleType(VehicleType.CAR)
.build());
// 2. Truck routing with dimensions
RouteResult truckRoute = service.calculateRoute(origin, destination, RoutingOptions.builder()
.vehicleType(VehicleType.TRUCK)
.truckWeight(18000) // 18 tons in kg
.truckHeight(400) // 4 meters in cm
.build());
// 3. Quick distance and duration estimation
DistanceTime dt = service.getDistanceTime(origin, destination, VehicleType.CAR);
double meters = dt.getDistance();
double seconds = dt.getDuration();
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classSimple distance/time result. -
Field Summary
Fields inherited from class com.cercalia.sdk.CercaliaClient
config, httpClient, logger, objectMapper -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NotNull RouteResultcalculateRoute(@NotNull Coordinate origin, @NotNull Coordinate destination, @Nullable RoutingOptions options) Calculate a route between origin and destination.@NotNull CompletableFuture<RouteResult>calculateRouteAsync(@NotNull Coordinate origin, @NotNull Coordinate destination, @Nullable RoutingOptions options) Calculate a route asynchronously.@NotNull RoutingService.DistanceTimegetDistanceTime(@NotNull Coordinate origin, @NotNull Coordinate destination, @Nullable VehicleType vehicleType) Get distance and duration between two points (without full geometry).@NotNull CompletableFuture<RoutingService.DistanceTime>getDistanceTimeAsync(@NotNull Coordinate origin, @NotNull Coordinate destination, @Nullable VehicleType vehicleType) Get distance and duration asynchronously.Methods inherited from class com.cercalia.sdk.CercaliaClient
addIfPresent, addIfPresent, addIfPresent, addIfTrue, getConfig, newParams, newParams, request, request, requestAsync, requestAsync
-
Constructor Details
-
RoutingService
-
-
Method Details
-
calculateRoute
@NotNull public @NotNull RouteResult calculateRoute(@NotNull @NotNull Coordinate origin, @NotNull @NotNull Coordinate destination, @Nullable @Nullable RoutingOptions options) Calculate a route between origin and destination.- Parameters:
origin- starting pointdestination- ending pointoptions- routing options (optional)- Returns:
- route result with geometry, distance and duration
- Throws:
CercaliaException- if the request fails
-
calculateRouteAsync
@NotNull public @NotNull CompletableFuture<RouteResult> calculateRouteAsync(@NotNull @NotNull Coordinate origin, @NotNull @NotNull Coordinate destination, @Nullable @Nullable RoutingOptions options) Calculate a route asynchronously. -
getDistanceTime
@NotNull public @NotNull RoutingService.DistanceTime getDistanceTime(@NotNull @NotNull Coordinate origin, @NotNull @NotNull Coordinate destination, @Nullable @Nullable VehicleType vehicleType) Get distance and duration between two points (without full geometry).- Parameters:
origin- starting pointdestination- ending pointvehicleType- vehicle type (optional)- Returns:
- distance in meters and duration in seconds
- Throws:
CercaliaException- if the request fails
-
getDistanceTimeAsync
@NotNull public @NotNull CompletableFuture<RoutingService.DistanceTime> getDistanceTimeAsync(@NotNull @NotNull Coordinate origin, @NotNull @NotNull Coordinate destination, @Nullable @Nullable VehicleType vehicleType) Get distance and duration asynchronously.
-