Skip to content

Commit c89a062

Browse files
author
Cameron Mace
authored
Updated optimization API (#506)
* updated optimization API * deprecated misspelled method * fixed up optimization waypoint object
1 parent 200ce88 commit c89a062

13 files changed

Lines changed: 6867 additions & 13623 deletions

File tree

Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,9 @@ optimized-trips-fixtures:
120120
# request an optimized car trip with no additional options
121121
curl "https://api.mapbox.com/optimized-trips/v1/mapbox/driving/-122.42,37.78;-122.45,37.91;-122.48,37.73?access_token=$(MAPBOX_ACCESS_TOKEN)" \
122122
-o mapbox/libjava-services/src/test/fixtures/optimized_trip.json
123+
124+
curl "https://api.mapbox.com/optimized-trips/v1/mapbox/cycling/-122.42,37.78;-122.45,37.91;-122.48,37.73?steps=true&language=sv&access_token=$(MAPBOX_ACCESS_TOKEN)" \
125+
-o mapbox/libjava-services/src/test/fixtures/optimized_trip_steps.json
126+
127+
curl "https://api.mapbox.com/optimized-trips/v1/mapbox/driving/13.388860,52.517037;13.397634,52.529407;13.428555,52.523219;13.418555,52.523215?roundtrip=true&distributions=3,1&access_token=$(MAPBOX_ACCESS_TOKEN)" \
128+
-o mapbox/libjava-services/src/test/fixtures/optimized_trip_distributions.json

mapbox/libjava-services-rx/src/main/java/com/mapbox/services/api/rx/optimizedtrips/v1/MapboxOptimizedTripsRx.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ public Observable<OptimizedTripsResponse> getObservable() {
7272
builder.getGeometries(),
7373
builder.getAnnotation(),
7474
builder.getDestination(),
75-
builder.getSource());
75+
builder.getSource(),
76+
builder.getLanguage(),
77+
builder.getDistributions());
7678

7779
// Done
7880
return observable;

mapbox/libjava-services-rx/src/main/java/com/mapbox/services/api/rx/optimizedtrips/v1/OptimizedTripsServiceRx.java

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,28 @@
1616
public interface OptimizedTripsServiceRx {
1717

1818
/**
19-
* @param userAgent The user.
20-
* @param user The user.
21-
* @param profile The profile directions should use.
22-
* @param coordinates The coordinates used to calculate the trip.
23-
* @param accessToken Mapbox access token.
24-
* @param roundTrip Returned route is a roundtrip (route returns to first location). Allowed values are: true
25-
* (default) or false.
26-
* @param radiuses Maximum distance in meters that each coordinate is allowed to move when snapped to a nearby
27-
* road segment. There must be as many radiuses as there are coordinates in the request. Values
28-
* can be any number greater than 0 or they can be the string unlimited. If no routable road is
29-
* found within the radius, a NoSegment error is returned.
30-
* @param bearings Used to filter the road segment the waypoint will be placed on by direction and dictates
31-
* the angle of approach
32-
* @param steps Define if you'd like the route steps.
33-
* @param geometries Route geometry.
34-
* @param annotations An annotations object that contains additional details about each line segment along the
35-
* route geometry. Each entry in an annotations field corresponds to a coordinate along the
36-
* route geometry.
37-
* @param destination Returned route ends at any or last coordinate. Allowed values are: any (default) or last.
38-
* @param source Returned route starts at any or first coordinate. Allowed values are: any (default) or first.
19+
* @param userAgent The user.
20+
* @param user The user.
21+
* @param profile The profile directions should use.
22+
* @param coordinates The coordinates used to calculate the trip.
23+
* @param accessToken Mapbox access token.
24+
* @param roundTrip Returned route is a roundtrip (route returns to first location). Allowed values are: true
25+
* (default) or false.
26+
* @param radiuses Maximum distance in meters that each coordinate is allowed to move when snapped to a nearby
27+
* road segment. There must be as many radiuses as there are coordinates in the request. Values
28+
* can be any number greater than 0 or they can be the string unlimited. If no routable road is
29+
* found within the radius, a NoSegment error is returned.
30+
* @param bearings Used to filter the road segment the waypoint will be placed on by direction and dictates
31+
* the angle of approach
32+
* @param steps Define if you'd like the route steps.
33+
* @param geometries Route geometry.
34+
* @param annotations An annotations object that contains additional details about each line segment along the
35+
* route geometry. Each entry in an annotations field corresponds to a coordinate along the
36+
* route geometry.
37+
* @param destination Returned route ends at any or last coordinate. Allowed values are: any (default) or last.
38+
* @param source Returned route starts at any or first coordinate. Allowed values are: any (default) or first.
39+
* @param language Language of returned turn-by-turn text instructions.
40+
* @param distributions Specify pick-up and drop-off locations
3941
* @since 2.1.0
4042
*/
4143
@GET("optimized-trips/v1/{user}/{profile}/{coordinates}")
@@ -46,13 +48,15 @@ Observable<OptimizedTripsResponse> getObservable(
4648
@Path("coordinates") String coordinates,
4749
@Query("access_token") String accessToken,
4850
@Query("roundtrip") Boolean roundTrip,
49-
@Query("radiuses") double[] radiuses,
50-
@Query("bearings") double[][] bearings,
51+
@Query("radiuses") String radiuses,
52+
@Query("bearings") String bearings,
5153
@Query("steps") Boolean steps,
5254
@Query("overview") String overview,
5355
@Query("geometries") String geometries,
5456
@Query("annotations") String[] annotations,
5557
@Query("destination") String destination,
56-
@Query("source") String source
58+
@Query("source") String source,
59+
@Query("language") String language,
60+
@Query("distributions") String distributions
5761
);
5862
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void setName(String name) {
4141
}
4242

4343
/**
44-
* an array with two double values reresenting the maneuver locations coordinate.
44+
* an array with two double values representing the maneuver locations coordinate.
4545
*
4646
* @return double array of [longitude, latitude] for the snapped coordinate.
4747
* @since 1.0.0

mapbox/libjava-services/src/main/java/com/mapbox/services/api/mapmatching/v5/models/MapMatchingTracepoint.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public class MapMatchingTracepoint extends DirectionsWaypoint {
1515
@SerializedName("waypoint_index")
1616
private int waypointIndex;
1717

18+
/**
19+
* Public constructor
20+
*/
1821
public MapMatchingTracepoint() {
1922
}
2023

@@ -28,6 +31,7 @@ public MapMatchingTracepoint(int matchingsIndex, int alternativesCount, int wayp
2831
* Index to the match object in matchings the sub-trace was matched to.
2932
*
3033
* @return index value
34+
* @since 2.2.0
3135
*/
3236
public int getMatchingsIndex() {
3337
return matchingsIndex;
@@ -37,6 +41,7 @@ public int getMatchingsIndex() {
3741
* Index value
3842
*
3943
* @param matchingsIndex value
44+
* @since 2.2.0
4045
*/
4146
public void setMatchingsIndex(int matchingsIndex) {
4247
this.matchingsIndex = matchingsIndex;
@@ -46,6 +51,7 @@ public void setMatchingsIndex(int matchingsIndex) {
4651
* Index of the waypoint inside the matched route.
4752
*
4853
* @return index value
54+
* @since 2.2.0
4955
*/
5056
public int getWaypointIndex() {
5157
return waypointIndex;

mapbox/libjava-services/src/main/java/com/mapbox/services/api/optimizedtrips/v1/MapboxOptimizedTrips.java

Lines changed: 140 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ private Call<OptimizedTripsResponse> getCall() {
8585
builder.getGeometries(),
8686
builder.getAnnotation(),
8787
builder.getDestination(),
88-
builder.getSource());
88+
builder.getSource(),
89+
builder.getLanguage(),
90+
builder.getDistributions());
8991

9092
// Done
9193
return call;
@@ -153,8 +155,10 @@ public static class Builder<T extends Builder> extends MapboxBuilder {
153155
private double[] radiuses;
154156
private Boolean steps;
155157
private double[][] bearings;
156-
private String[] annotation;
158+
private String[] annotations;
157159
private String overview;
160+
private String language;
161+
private double[][] distributions;
158162

159163
/**
160164
* Constructor
@@ -340,15 +344,32 @@ public T setBearings(double[]... bearings) {
340344
/**
341345
* Whether or not to return additional metadata along the route. Possible values are:
342346
* {@link DirectionsCriteria#ANNOTATION_DISTANCE}, {@link DirectionsCriteria#ANNOTATION_DURATION}, and
343-
* {@link DirectionsCriteria#ANNOTATION_SPEED}. Several annotation can be used by separating them with {@code ,}.
347+
* {@link DirectionsCriteria#ANNOTATION_SPEED}. Several annotations can be used by separating them with {@code ,}.
344348
*
345-
* @param annotation String referencing one of the annotation direction criteria's.
349+
* @param annotation String referencing one of the annotations direction criteria's.
346350
* @return Builder
347351
* @see <a href="https://www.mapbox.com/api-documentation/#routeleg-object">RouteLeg object documentation</a>
348352
* @since 2.1.0
353+
* @deprecated use {@link Builder#getAnnotations()} instead
349354
*/
355+
@Deprecated
350356
public T setAnnotation(String... annotation) {
351-
this.annotation = annotation;
357+
this.annotations = annotation;
358+
return (T) this;
359+
}
360+
361+
/**
362+
* Whether or not to return additional metadata along the route. Possible values are:
363+
* {@link DirectionsCriteria#ANNOTATION_DISTANCE}, {@link DirectionsCriteria#ANNOTATION_DURATION}, and
364+
* {@link DirectionsCriteria#ANNOTATION_SPEED}. Several annotations can be used by separating them with {@code ,}.
365+
*
366+
* @param annotation String referencing one of the annotations direction criteria's.
367+
* @return Builder
368+
* @see <a href="https://www.mapbox.com/api-documentation/#routeleg-object">RouteLeg object documentation</a>
369+
* @since 2.1.0
370+
*/
371+
public T setAnnotations(String... annotation) {
372+
this.annotations = annotation;
352373
return (T) this;
353374
}
354375

@@ -376,6 +397,38 @@ public T setClientAppName(String appName) {
376397
return (T) this;
377398
}
378399

400+
/**
401+
* Optionally set the language of returned turn-by-turn text instructions. The default is {@code en} for English.
402+
*
403+
* @param language The locale in which results should be returned.
404+
* @return Builder
405+
* @see <a href="https://www.mapbox.com/api-documentation/#instructions-languages">Supported languages</a>
406+
* @since 2.2.0
407+
*/
408+
public T setLanguage(String language) {
409+
this.language = language;
410+
return (T) this;
411+
}
412+
413+
/**
414+
* Specify pick-up and drop-off locations for a trip by providing a {@code double[]} each with a number pair that
415+
* correspond with the coordinates list. The first number indicates what place the coordinate of the pick-up
416+
* location is in the coordinates list, and the second number indicates what place the coordinate of the drop-off
417+
* location is in the coordinates list. Each pair must contain exactly two numbers. Pick-up and drop-off locations
418+
* in one pair cannot be the same. The returned solution will visit pick-up locations before visiting drop-off
419+
* locations. The depot (first location) can only be a pick-up location but not a drop-off location.
420+
*
421+
* @param distributions {@code double[]} with two values, first being the pickup coordinate in the coordinates list
422+
* and the second number being the coordinate in the coordinates list which should be the drop
423+
* off location.
424+
* @return Builder
425+
* @since 2.2.0
426+
*/
427+
public T setDistributions(double[]... distributions) {
428+
this.distributions = distributions;
429+
return (T) this;
430+
}
431+
379432
/*
380433
* Getters
381434
*/
@@ -462,11 +515,24 @@ public String getGeometries() {
462515
* Get the maximum distance in meters you have set that each coordinate is allowed to move when snapped to a nearby
463516
* road segment.
464517
*
465-
* @return double array containing the radiuses defined in unit meters.
518+
* @return String containing the radiuses defined in unit meters.
466519
* @since 2.1.0
467520
*/
468-
public double[] getRadiuses() {
469-
return radiuses;
521+
public String getRadiuses() {
522+
if (radiuses == null || radiuses.length == 0) {
523+
return null;
524+
}
525+
526+
String[] radiusesFormatted = new String[radiuses.length];
527+
for (int i = 0; i < radiuses.length; i++) {
528+
if (radiuses[i] == Double.POSITIVE_INFINITY) {
529+
radiusesFormatted[i] = "unlimited";
530+
} else {
531+
radiusesFormatted[i] = String.format(Locale.US, "%s", TextUtils.formatCoordinate(radiuses[i]));
532+
}
533+
}
534+
535+
return TextUtils.join(";", radiusesFormatted);
470536
}
471537

472538
/**
@@ -502,24 +568,52 @@ public Boolean getSteps() {
502568
* Determine whether you are filtering the road segment the waypoint will be placed on by direction and dictating
503569
* the angle of approach.
504570
*
505-
* @return a double array with two values indicating the angle and the other value indicating the deviating
571+
* @return String with two values indicating the angle and the other value indicating the deviating
506572
* range.
507573
* @since 2.1.0
508574
*/
509-
public double[][] getBearings() {
510-
return bearings;
575+
public String getBearings() {
576+
if (bearings == null || bearings.length == 0) {
577+
return null;
578+
}
579+
580+
String[] bearingFormatted = new String[bearings.length];
581+
for (int i = 0; i < bearings.length; i++) {
582+
if (bearings[i].length == 0) {
583+
bearingFormatted[i] = "";
584+
} else {
585+
bearingFormatted[i] = String.format(Locale.US, "%s,%s",
586+
TextUtils.formatCoordinate(bearings[i][0]),
587+
TextUtils.formatCoordinate(bearings[i][1]));
588+
}
589+
}
590+
return TextUtils.join(";", bearingFormatted);
511591
}
512592

513593
/**
514594
* Determine whether or not you are currently requesting additional metadata along the route. Possible values are:
515595
* {@link DirectionsCriteria#ANNOTATION_DISTANCE}, {@link DirectionsCriteria#ANNOTATION_DURATION}, and
516-
* {@link DirectionsCriteria#ANNOTATION_SPEED}. Several annotation can be used by separating them with {@code ,}.
596+
* {@link DirectionsCriteria#ANNOTATION_SPEED}. Several annotations can be used by separating them with {@code ,}.
517597
*
518-
* @return String referencing one of the annotation direction criteria's.
598+
* @return String referencing one of the annotations direction criteria's.
519599
* @since 2.1.0
600+
* @deprecated Use {@link Builder#getAnnotations()}
520601
*/
602+
@Deprecated
521603
public String[] getAnnotation() {
522-
return annotation;
604+
return annotations;
605+
}
606+
607+
/**
608+
* Determine whether or not you are currently requesting additional metadata along the route. Possible values are:
609+
* {@link DirectionsCriteria#ANNOTATION_DISTANCE}, {@link DirectionsCriteria#ANNOTATION_DURATION}, and
610+
* {@link DirectionsCriteria#ANNOTATION_SPEED}. Several annotations can be used by separating them with {@code ,}.
611+
*
612+
* @return String referencing one of the annotations direction criteria's.
613+
* @since 2.1.0
614+
*/
615+
public String[] getAnnotations() {
616+
return annotations;
523617
}
524618

525619
/**
@@ -531,6 +625,38 @@ public String getAccessToken() {
531625
return accessToken;
532626
}
533627

628+
/**
629+
* @return The language the turn-by-turn directions will be in.
630+
* @since 2.2.0
631+
*/
632+
public String getLanguage() {
633+
return language;
634+
}
635+
636+
/**
637+
* If distribution values are set inside your request, this will return a String containing the given values.
638+
*
639+
* @return String containing the provided distribution values.
640+
* @since 2.2.0
641+
*/
642+
public String getDistributions() {
643+
if (distributions == null || distributions.length == 0) {
644+
return null;
645+
}
646+
647+
String[] distributionsFormatted = new String[distributions.length];
648+
for (int i = 0; i < distributions.length; i++) {
649+
if (distributions[i].length == 0) {
650+
distributionsFormatted[i] = "";
651+
} else {
652+
distributionsFormatted[i] = String.format(Locale.US, "%s,%s",
653+
TextUtils.formatCoordinate(distributions[i][0]),
654+
TextUtils.formatCoordinate(distributions[i][1]));
655+
}
656+
}
657+
return TextUtils.join(";", distributionsFormatted);
658+
}
659+
534660
/**
535661
* Build method
536662
*

0 commit comments

Comments
 (0)