THIS SDK ISDEPRECATED. We rolled out a new and better SDK for you.
The Reachable Range component calculates a set of locations that can be reached from the origin
point. It optimizes routes with a given route-type (e.g., fastest, eco, etc.) but limits the range
for the given budget and consumption parameters. It uses
the Calculate Reachable Range API
so you can find all details in the service documentation.
Sample use case: You are preparing for a trip and you would like to check how far you can drive
on your battery or tank, or within a specific time limit so you can plan your journey.
The following example shows a number of points that are reachable based on one of a specified model
for: * Combustion engine * Electric engine * Time-2h limit on an electric car (time budget model
is available for both electric and combustion engines)
Use the following code sample to implement a similar use case.
To request a reachable range, create a ReachableRangeSpecification
:
Creating ReachableRangeSpecification
for a combustion vehicle can be done in the following manner:
Copy 1 return new ReachableRangeSpecification . Builder ( Locations . AMSTERDAM_CENTER_LOCATION )
2 . reachableRangeBudgetDescriptor ( reachableRangeBudgetDescriptor )
3 . combustionVehicleDescriptor ( combustionVehicleDescriptor )
Copy 1 return ReachableRangeSpecification . Builder ( Locations . AMSTERDAM_CENTER )
2 . reachableRangeBudgetDescriptor ( reachableRangeBudgetDescriptor )
3 . combustionVehicleDescriptor ( createCombustionVehicleDescriptor ( ) )
Creating ReachableRangeSpecification
for the electric vehicle can be done in the following manner:
Copy 1 return new ReachableRangeSpecification . Builder ( Locations . AMSTERDAM_CENTER_LOCATION )
2 . reachableRangeBudgetDescriptor ( reachableRangeBudgetDescriptor )
3 . electricVehicleDescriptor ( electricVehicleDescriptor )
Copy 1 return ReachableRangeSpecification . Builder ( Locations . AMSTERDAM_CENTER )
2 . reachableRangeBudgetDescriptor ( reachableRangeBudgetDescriptor )
3 . electricVehicleDescriptor ( createElectricVehicleDescriptor ( ) )
and pass it to the Routing API:
Copy 1 routingApi . planReachableRange (
2 reachableRangeSpecificationFactory . createReachableRangeSpecificationForCombustion ( ) ,
3 reachableAreaCallback ) ;
Copy routingApi . planReachableRange ( reachableRangeSpecification , reachableAreaCallback )
Setup of the common parameters of the ReachableRangeSpecification
for a combustion engine:
Copy 1 ReachableRangeBudgetDescriptor reachableRangeBudgetDescriptor =
2 new ReachableRangeBudgetDescriptor . Builder ( )
3 . fuelBudgetInLiters ( 5.0 )
6 Map < Double , Double > consumptionMap = new HashMap < > ( ) ;
7 consumptionMap . put ( 50.0 , 6.3 ) ;
9 CombustionVehicleConsumption combustionVehicleConsumption = new CombustionVehicleConsumption (
10 43.0 , 1.7 , 34.2 , consumptionMap
13 CombustionVehicleDescriptor combustionVehicleDescriptor = new CombustionVehicleDescriptor . Builder ( )
14 . vehicleConsumption ( combustionVehicleConsumption )
15 . vehicleDimensions ( new VehicleDimensions . Builder ( )
16 . vehicleWeightInKg ( 1600 )
18 . vehicleEfficiency ( new VehicleEfficiency . Builder ( )
19 . uphillEfficiency ( 0.33 )
20 . downhillEfficiency ( 0.33 )
21 . decelerationEfficiency ( 0.33 )
22 . accelerationEfficiency ( 0.33 )
Copy 1 val consumption = mapOf ( Pair ( SPEED , CONSUMPTION_AT_SPEED ) )
2 val combustionVehicleConsumption = CombustionVehicleConsumption (
3 VEHICLE_CURRENT_FUEL , VEHICLE_AUXILIARY_POWER , FUEL_ENERGY_DENSITY , consumption
6 return CombustionVehicleDescriptor . Builder ( )
7 . vehicleConsumption ( combustionVehicleConsumption )
8 . vehicleEfficiency ( createVehicleEfficiency ( ) )
9 . vehicleDimensions ( createVehicleDimensions ( ) )
Setup of the common parameters of the ReachableRangeSpecification
for an electric vehicle:
Copy 1 ReachableRangeBudgetDescriptor reachableRangeBudgetDescriptor =
2 new ReachableRangeBudgetDescriptor . Builder ( )
3 . energyBudgetInKWh ( 5.0 )
5 Map < Double , Double > consumptionMap = new HashMap < > ( ) ;
6 consumptionMap . put ( 50.0 , 6.3 ) ;
8 ElectricVehicleConsumption electricVehicleConsumption =
9 new ElectricVehicleConsumption ( 85.0 , 43.0 , 1.7 , consumptionMap ) ;
11 ElectricVehicleDescriptor electricVehicleDescriptor = new ElectricVehicleDescriptor . Builder ( electricVehicleConsumption )
12 . vehicleDimensions ( new VehicleDimensions . Builder ( )
13 . vehicleWeightInKg ( 1600 )
15 . vehicleEfficiency ( new VehicleEfficiency . Builder ( )
16 . uphillEfficiency ( 0.33 )
17 . downhillEfficiency ( 0.33 )
18 . decelerationEfficiency ( 0.33 )
19 . accelerationEfficiency ( 0.33 )
Copy 1 val consumption = mapOf ( Pair ( SPEED , CONSUMPTION_AT_SPEED ) )
2 val electricVehicleConsumption = ElectricVehicleConsumption (
3 VEHICLE_MAX_CHARGE , VEHICLE_CURRENT_CHARGE , VEHICLE_AUXILIARY_POWER , consumption
6 return ElectricVehicleDescriptor . Builder ( electricVehicleConsumption )
7 . vehicleEfficiency ( createVehicleEfficiency ( ) )
8 . vehicleDimensions ( createVehicleDimensions ( ) )
The result can be observed with ReachableAreaCallback:
Copy 1 protected ReachableAreaCallback reachableAreaCallback = new ReachableAreaCallback ( ) {
3 public void onSuccess ( @NonNull ReachableRangeArea reachableArea ) {
4 doActionOnReachableRangeResponse ( reachableArea ) ;
8 public void onError ( @NonNull RoutingException error ) {
9 doActionOnReachableRangeError ( ) ;
Copy 1 private val reachableAreaCallback = object : ReachableAreaCallback {
2 override fun onSuccess ( reachableArea : ReachableRangeArea ) {
3 reachableRangeArea . value = Resource . success ( reachableArea )
6 override fun onError ( error : RoutingException ) {
7 reachableRangeArea . value = Resource . error ( null , Error ( error . message ) )
Fuel budget: 5 liters
Energy budget: 5 kWh
Time budget: 2h
You can use the output of the returned set of locations for other interacting use cases e.g.,
searching for places on the route to one (many) reachable point(s) with Search along the route or
within the polygon boundaries with the Geometry search features of the Maps SDK.