Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ directions-fixtures:
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-122.416667,37.783333;-121.900000,37.333333?geometries=polyline&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
-o mapbox/libjava-services/src/test/fixtures/directions_v5.json

directions-traffic-fixtures:
curl "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/-122.416667,37.783333;-121.900000,37.333333?geometries=polyline&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
-o mapbox/libjava-services/src/test/fixtures/directions_v5_traffic.json

mapmatching-fixtures:
# Geometry polyline
curl -X POST --header "Content-Type:application/json" -d @mapbox/libjava-services/src/test/fixtures/mapmatching_trace.json \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ public class DirectionsCriteria {

public static final String PROFILE_DEFAULT_USER = "mapbox";

/**
* For car and motorcycle routing. This profile factors in current and historic traffic
* conditions to avoid slowdowns.
*
* @since 2.0.0
*/
public static final String PROFILE_DRIVING_TRAFFIC = "driving-traffic";

/**
* For car and motorcycle routing. This profile shows the fastest routes by preferring
* high-speed roads like highways.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ public String getUser() {
}

/**
* @return {@link com.mapbox.services.api.directions.v5.DirectionsCriteria#PROFILE_DRIVING},
* @return {@link com.mapbox.services.api.directions.v5.DirectionsCriteria#PROFILE_DRIVING_TRAFFIC},
* {@link com.mapbox.services.api.directions.v5.DirectionsCriteria#PROFILE_DRIVING},
* {@link com.mapbox.services.api.directions.v5.DirectionsCriteria#PROFILE_CYCLING},
* or {@link com.mapbox.services.api.directions.v5.DirectionsCriteria#PROFILE_WALKING}
* @since 1.0.0
Expand Down Expand Up @@ -459,11 +460,28 @@ public Builder setBaseUrl(String baseUrl) {
public MapboxDirections build() throws ServicesException {
validateAccessToken(accessToken);

if (profile == null) {
throw new ServicesException(
"A profile is required for the Directions API. Use one of the profiles found in the"
+ "DirectionsCriteria.java file.");
}

if (coordinates == null || coordinates.size() < 2) {
throw new ServicesException(
"You should provide at least two coordinates (from/to).");
}

if (profile.equals(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC)
&& coordinates.size() > 3) {
throw new ServicesException(
"Using the driving-traffic profile allows for maximum of 3 coordinates.");
}

if (coordinates.size() > 25) {
throw new ServicesException(
"All profiles (except driving-traffic) allows for maximum of 25 coordinates.");
}

if (radiuses != null && radiuses.length != coordinates.size()) {
throw new ServicesException(
"There must be as many radiuses as there are coordinates.");
Expand Down
Loading