Skip to content
This repository was archived by the owner on Jan 9, 2019. It is now read-only.

Commit 2cd5ab8

Browse files
author
Mustafa Shabib
authored
Merge pull request #1 from quartethealth/feature/add-annotations-to-matrix-service
Updates Matrix service.
2 parents 0890444 + 5791aca commit 2cd5ab8

File tree

4 files changed

+55
-2
lines changed

4 files changed

+55
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
## Changelog for Mapbox Java and Android Services
22

33
Mapbox welcomes participation and contributions from everyone.
4+
### v4.0.1 - September 27, 2018
5+
- Allows for annotations to be passed to the MatrixService and returns distances matrix in addition to durations matrix
6+
47
### v4.0.0 - September 19, 2018
58
- downgrade to java 7 #876
69
- The first and last positions should be equivalent in polygon ring Bug Ready For Review refactor #886

services-matrix/src/main/java/com/mapbox/api/matrix/v1/MapboxMatrix.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ protected Call<MatrixResponse> initializeCall() {
6666
coordinates(),
6767
accessToken(),
6868
destinations(),
69-
sources());
69+
sources(),
70+
annotations());
7071
}
7172

7273
@Nullable
@@ -90,6 +91,9 @@ protected Call<MatrixResponse> initializeCall() {
9091
@Nullable
9192
abstract String destinations();
9293

94+
@Nullable
95+
abstract String annotations();
96+
9397
@NonNull
9498
@Override
9599
protected abstract String baseUrl();
@@ -128,6 +132,7 @@ public abstract static class Builder {
128132
private List<Point> coordinates = new ArrayList<>();
129133
private Integer[] destinations;
130134
private Integer[] sources;
135+
private String[] annotations;
131136

132137
/**
133138
* The username for the account that the directions engine runs on. In most cases, this should
@@ -158,6 +163,22 @@ public Builder coordinates(List<Point> coordinates) {
158163
// Required for matching with MapboxMatrix coordinates() method.
159164
abstract Builder coordinates(@NonNull String coordinates);
160165

166+
/**
167+
* Optionally pass in annotations to specify the resulting matrices. Possible values are:
168+
* duration (default), distance , or both values separated by comma.
169+
*
170+
* @param annotations "duration", "distance", or "duration,distance"
171+
* @return this builder for chaining options together
172+
* @since 2.1.0
173+
*/
174+
public Builder annotations(@Nullable String... annotations) {
175+
this.annotations = annotations;
176+
return this;
177+
}
178+
179+
// Required for matching with MapboxMatrix annotations() method.
180+
abstract Builder annotations(@Nullable String annotations);
181+
161182
/**
162183
* This will add a single {@link Point} to the coordinate list which is used to determine the
163184
* duration between points. This can be called up to 25 times until you hit the maximum allowed
@@ -264,6 +285,7 @@ public MapboxMatrix build() {
264285

265286
sources(TextUtils.join(";", sources));
266287
destinations(TextUtils.join(";", destinations));
288+
annotations(TextUtils.join(",", annotations));
267289

268290
// Generate build so that we can check that values are valid.
269291
MapboxMatrix matrix = autoBuild();

services-matrix/src/main/java/com/mapbox/api/matrix/v1/MatrixService.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ public interface MatrixService {
3131
* the road and path network. The waypoints appear in the array in the order
3232
* of the input coordinates, or in the order as specified in the sources query
3333
* parameter
34+
* @param annotations Used to specify the resulting matrices. Possible values are: duration
35+
* (default), distance , or both values separated by comma.
36+
*
3437
* @return the {@link MatrixResponse} in a Call wrapper
3538
* @since 2.1.0
3639
*/
@@ -43,6 +46,7 @@ Call<MatrixResponse> getCall(
4346
@Path("coordinates") String coordinates,
4447
@Query("access_token") String accessToken,
4548
@Query("destinations") String destinations,
46-
@Query("sources") String sources
49+
@Query("sources") String sources,
50+
@Query("annotations") String annotations
4751
);
4852
}

services-matrix/src/main/java/com/mapbox/api/matrix/v1/models/MatrixResponse.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ public static Builder builder() {
8383
@Nullable
8484
public abstract List<Double[]> durations();
8585

86+
/**
87+
* Distances as an array of arrays that represent the matrix in row-major order. distances[i][j]
88+
* gives the travel distance from the i th source to the j th destination. All values are i
89+
* meters. The distance between the same coordinate is always 0 . If a distance cannot be found
90+
* the result is null .
91+
*
92+
* @return an array of array with each entry being a distance value given in meters.
93+
* @since 2.1.1
94+
*/
95+
@Nullable
96+
public abstract List<Double[]> distances();
97+
8698
/**
8799
* Convert the current {@link MatrixResponse} to its builder holding the currently assigned
88100
* values. This allows you to modify a single variable and then rebuild the object resulting in
@@ -167,6 +179,18 @@ public abstract static class Builder {
167179
*/
168180
public abstract Builder durations(@Nullable List<Double[]> durations);
169181

182+
/**
183+
* Distances as array of arrays representing the matrix in row-major order. distances[i][j]
184+
* gives the travel time from the i-th source to the j-th destination. All values are in
185+
* meters. The duration between the same coordinate is always 0. If a distance can not be
186+
* found, the result is null.
187+
*
188+
* @param distances an array of array with each entry being a distance value given in meters.
189+
* @return this builder for chaining options together
190+
* @since 2.1.1
191+
*/
192+
public abstract Builder distances(@Nullable List<Double[]> distances);
193+
170194
/**
171195
* Build a new {@link MatrixResponse} object.
172196
*

0 commit comments

Comments
 (0)