Class RoutingService

java.lang.Object
com.cercalia.sdk.CercaliaClient
com.cercalia.sdk.services.RoutingService

public class RoutingService extends CercaliaClient
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:
  • Constructor Details

    • RoutingService

      public RoutingService(@NotNull @NotNull CercaliaConfig config)
  • 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 point
      destination - ending point
      options - 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 point
      destination - ending point
      vehicleType - 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.