Skip to main content
The SDK provides two routing operations:
  • Directions — returns full route information including steps and step paths between one origin and one destination.
  • ETA — returns travel time and distance estimates from one origin to up to 10 destinations.

Directions

Build a DirectionsInput with an origin and destination, then call api.directions().
DirectionsEndpoint origin = DirectionsEndpoint.fromLatitudeLongitude(53.551666, 9.9942163);
DirectionsEndpoint destination = DirectionsEndpoint.fromLatitudeLongitude(53.558, 10.0);

try (AppleMaps api = new AppleMaps(token)) {
    DirectionsResponse response = api.directions(
        DirectionsInput.builder(origin, destination).build()
    );
    response.routes().forEach(route -> System.out.println(route.durationSeconds()));
}

Creating endpoints

DirectionsEndpoint represents either coordinate pair or a free-form address:
// From coordinates
DirectionsEndpoint fromCoords = DirectionsEndpoint.fromLatitudeLongitude(37.7796095, -122.4016725);

// From an address string
DirectionsEndpoint fromAddress = DirectionsEndpoint.fromAddress("880 Harrison St, San Francisco, CA 94107");

DirectionsInput builder options

DirectionsInput.builder(origin, destination) accepts:
MethodTypeDescription
.transportType(TransportType)TransportTypeOne of AUTOMOBILE, TRANSIT, WALKING, CYCLING.
.avoid(List<DirectionsAvoid>)DirectionsAvoidRoute features to avoid. Currently supports TOLLS.
.departureDate(String)StringDeparture date/time in the format the API expects.
.arrivalDate(String)StringArrival date/time. Cannot be combined with departureDate.
.requestsAlternateRoutes(Boolean)BooleanRequest additional route options.
.language(String)BCP 47 tagResponse language for step instructions.
.userLocation(RouteLocation)RouteLocationHint the user’s position for disambiguation.
.searchLocation(RouteLocation)RouteLocationBias address resolution toward a coordinate.
.searchRegion(SearchRegion)SearchRegionConstrain address resolution to a region.
You may set either departureDate or arrivalDate, but not both. Passing both throws IllegalArgumentException at build time.
Example — driving route avoiding tolls:
DirectionsResponse response = api.directions(
    DirectionsInput.builder(origin, destination)
        .transportType(TransportType.AUTOMOBILE)
        .avoid(List.of(DirectionsAvoid.TOLLS))
        .build()
);
Example — walking directions in French:
DirectionsResponse response = api.directions(
    DirectionsInput.builder(origin, destination)
        .transportType(TransportType.WALKING)
        .language("fr-FR")
        .build()
);

DirectionsResponse structure

FieldTypeDescription
routes()List<DirectionsRoute>One or more routes.
steps()List<DirectionsStep>All steps across all routes.
stepPaths()List<List<Location>>Coordinate arrays for rendering each step on a map.
origin()Optional<Place>Resolved origin place, if available.
destination()Optional<Place>Resolved destination place, if available.
Each DirectionsRoute contains:
FieldTypeDescription
name()Optional<String>Route name.
distanceMeters()Optional<Long>Total route distance in meters.
durationSeconds()Optional<Long>Estimated travel time in seconds.
hasTolls()Optional<Boolean>Whether the route passes through tolls.
stepIndexes()List<Integer>Indexes into the steps() list for this route.
transportType()Optional<TransportType>Transport mode used.
Each DirectionsStep contains:
FieldTypeDescription
instructions()Optional<String>Human-readable turn instruction.
distanceMeters()Optional<Long>Step distance in meters.
durationSeconds()Optional<Long>Step duration in seconds.
stepPathIndex()Optional<Integer>Index into stepPaths() for this step’s geometry.
transportType()Optional<TransportType>Transport mode for this step.

ETA

Request travel time estimates from one origin to multiple destinations. You can pass up to 10 destinations in a single call. EtaInput uses RouteLocation (not DirectionsEndpoint) for all coordinates:
RouteLocation origin = RouteLocation.fromLatitudeLongitude(53.551666, 9.9942163);
List<RouteLocation> destinations = List.of(
    RouteLocation.fromLatitudeLongitude(53.558, 10.0),
    RouteLocation.fromLatitudeLongitude(53.565, 9.985)
);

try (AppleMaps api = new AppleMaps(token)) {
    EtaResponse response = api.etas(
        EtaInput.builder(origin, destinations).build()
    );
    response.etas().forEach(eta -> System.out.println(eta.expectedTravelTimeSeconds()));
}

EtaInput builder options

EtaInput.builder(origin, destinations) accepts:
MethodTypeDescription
.transportType(TransportType)TransportTypeOne of AUTOMOBILE, TRANSIT, WALKING, CYCLING.
.departureDate(String)StringDeparture date/time.
.arrivalDate(String)StringArrival date/time.
Example — transit ETAs:
EtaResponse response = api.etas(
    EtaInput.builder(origin, destinations)
        .transportType(TransportType.TRANSIT)
        .build()
);

EtaResponse structure

EtaResponse.etas() returns a List<EtaEstimate>, one per destination in the same order as the input list. Each EtaEstimate contains:
FieldTypeDescription
destination()Optional<Location>The resolved destination coordinate.
distanceMeters()Optional<Long>Travel distance in meters.
expectedTravelTimeSeconds()Optional<Long>Travel time accounting for current traffic.
staticTravelTimeSeconds()Optional<Long>Travel time without traffic.
transportType()Optional<TransportType>Transport mode used.

RouteLocation vs. DirectionsEndpoint

TypeUsed inSupports address string
DirectionsEndpointDirectionsInputYes — fromAddress(String)
RouteLocationEtaInput, DirectionsInput hintsNo — coordinates only
Use DirectionsEndpoint.fromAddress() when you want Apple Maps to resolve a text address for a directions request. For ETA, coordinates are required via RouteLocation.fromLatitudeLongitude().