Skip to content

Commit 89a6b54

Browse files
srabenjaCameron Mace
authored andcommitted
mapbox/driving-traffic support added to the list of directions profil… (#292)
* mapbox/driving-traffic support added to the list of directions profiles; checks added for maximum number of coordinates provided * Check if a profile has been provided. Added a test for the driving-traffic response. * added tests and fixed up a few things
1 parent d6eefec commit 89a6b54

5 files changed

Lines changed: 2836 additions & 6 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ directions-fixtures:
8383
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)" \
8484
-o mapbox/libjava-services/src/test/fixtures/directions_v5.json
8585

86+
directions-traffic-fixtures:
87+
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)" \
88+
-o mapbox/libjava-services/src/test/fixtures/directions_v5_traffic.json
89+
8690
mapmatching-fixtures:
8791
# Geometry polyline
8892
curl -X POST --header "Content-Type:application/json" -d @mapbox/libjava-services/src/test/fixtures/mapmatching_trace.json \

mapbox/libjava-services/src/main/java/com/mapbox/services/api/directions/v5/DirectionsCriteria.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ public class DirectionsCriteria {
99

1010
public static final String PROFILE_DEFAULT_USER = "mapbox";
1111

12+
/**
13+
* For car and motorcycle routing. This profile factors in current and historic traffic
14+
* conditions to avoid slowdowns.
15+
*
16+
* @since 2.0.0
17+
*/
18+
public static final String PROFILE_DRIVING_TRAFFIC = "driving-traffic";
19+
1220
/**
1321
* For car and motorcycle routing. This profile shows the fastest routes by preferring
1422
* high-speed roads like highways.

mapbox/libjava-services/src/main/java/com/mapbox/services/api/directions/v5/MapboxDirections.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ public String getUser() {
325325
}
326326

327327
/**
328-
* @return {@link com.mapbox.services.api.directions.v5.DirectionsCriteria#PROFILE_DRIVING},
328+
* @return {@link com.mapbox.services.api.directions.v5.DirectionsCriteria#PROFILE_DRIVING_TRAFFIC},
329+
* {@link com.mapbox.services.api.directions.v5.DirectionsCriteria#PROFILE_DRIVING},
329330
* {@link com.mapbox.services.api.directions.v5.DirectionsCriteria#PROFILE_CYCLING},
330331
* or {@link com.mapbox.services.api.directions.v5.DirectionsCriteria#PROFILE_WALKING}
331332
* @since 1.0.0
@@ -459,11 +460,28 @@ public Builder setBaseUrl(String baseUrl) {
459460
public MapboxDirections build() throws ServicesException {
460461
validateAccessToken(accessToken);
461462

463+
if (profile == null) {
464+
throw new ServicesException(
465+
"A profile is required for the Directions API. Use one of the profiles found in the"
466+
+ "DirectionsCriteria.java file.");
467+
}
468+
462469
if (coordinates == null || coordinates.size() < 2) {
463470
throw new ServicesException(
464471
"You should provide at least two coordinates (from/to).");
465472
}
466473

474+
if (profile.equals(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC)
475+
&& coordinates.size() > 3) {
476+
throw new ServicesException(
477+
"Using the driving-traffic profile allows for maximum of 3 coordinates.");
478+
}
479+
480+
if (coordinates.size() > 25) {
481+
throw new ServicesException(
482+
"All profiles (except driving-traffic) allows for maximum of 25 coordinates.");
483+
}
484+
467485
if (radiuses != null && radiuses.length != coordinates.size()) {
468486
throw new ServicesException(
469487
"There must be as many radiuses as there are coordinates.");

0 commit comments

Comments
 (0)