Skip to content

Commit 36306ed

Browse files
authored
Add voiceUnits to MapMatching (mapbox#764)
* Add voiceUnits to MapMatching * Fix checkstyle
1 parent dfca45e commit 36306ed

3 files changed

Lines changed: 87 additions & 63 deletions

File tree

services-matching/src/main/java/com/mapbox/api/matching/v5/MapMatchingService.java

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,43 +19,44 @@ public interface MapMatchingService {
1919
* Constructs the html call using the information passed in through the
2020
* {@link MapboxMapMatching.Builder}.
2121
*
22-
* @param userAgent user agent
23-
* @param user user
24-
* @param profile directions profile ID; either mapbox/driving, mapbox/walking,
25-
* or mapbox/cycling
26-
* @param coordinates inaccurate traces from a GPS unit or a phone
27-
* @param accessToken Mapbox access token
28-
* @param geometries format of the returned geometry. Allowed values are: geojson
29-
* (as LineString), polyline with precision 5, polyline6. The default
30-
* value is polyline
31-
* @param radiuses a list of integers in meters indicating the assumed precision of
32-
* the used tracking device. There must be as many radiuses as there
33-
* are coordinates in the request, each separated by ;. Values can be
34-
* a number between 0 and 30. Use higher numbers (20-30) for noisy
35-
* traces and lower numbers (1-10) for clean traces. The default value
36-
* is 5
37-
* @param steps whether to return steps and turn-by-turn instructions. Can be true
38-
* or false. The default is false
39-
* @param overview type of returned overview geometry. Can be full (the most detailed
40-
* geometry available), simplified (a simplified version of the full
41-
* geometry), or false (no overview geometry). The default is simplified
42-
* @param timestamps timestamps corresponding to each coordinate provided in the request;
43-
* must be numbers in Unix time (seconds since the Unix epoch). There
44-
* must be as many timestamps as there are coordinates in the request,
45-
* each separated by {@code ;}
46-
* @param annotations whether or not to return additional metadata for each coordinate
47-
* along the match geometry. Can be one or all of 'duration', 'distance',
48-
* or 'nodes', each separated by ,. See the response object for more
49-
* details on what it is included with annotations
50-
* @param language language of returned turn-by-turn text instructions
51-
* @param tidy whether or not to transparently remove clusters and re-sample traces for
52-
* improved map matching results
53-
* @param roundaboutExits Whether or not to emit instructions at roundabout exits.
22+
* @param userAgent user agent
23+
* @param user user
24+
* @param profile directions profile ID; either mapbox/driving, mapbox/walking,
25+
* or mapbox/cycling
26+
* @param coordinates inaccurate traces from a GPS unit or a phone
27+
* @param accessToken Mapbox access token
28+
* @param geometries format of the returned geometry. Allowed values are: geojson
29+
* (as LineString), polyline with precision 5, polyline6. The default
30+
* value is polyline
31+
* @param radiuses a list of integers in meters indicating the assumed precision of
32+
* the used tracking device. There must be as many radiuses as there
33+
* are coordinates in the request, each separated by ;. Values can be
34+
* a number between 0 and 30. Use higher numbers (20-30) for noisy
35+
* traces and lower numbers (1-10) for clean traces. The default value
36+
* is 5
37+
* @param steps whether to return steps and turn-by-turn instructions. Can be true
38+
* or false. The default is false
39+
* @param overview type of returned overview geometry. Can be full (the most detailed
40+
* geometry available), simplified (a simplified version of the full
41+
* geometry), or false (no overview geometry). The default is simplified
42+
* @param timestamps timestamps corresponding to each coordinate provided in the request;
43+
* must be numbers in Unix time (seconds since the Unix epoch). There
44+
* must be as many timestamps as there are coordinates in the request,
45+
* each separated by {@code ;}
46+
* @param annotations whether or not to return additional metadata for each coordinate
47+
* along the match geometry. Can be one or all of 'duration',
48+
* 'distance', or 'nodes', each separated by ,. See the response
49+
* object for more details on what it is included with annotations
50+
* @param language language of returned turn-by-turn text instructions
51+
* @param tidy whether or not to transparently remove clusters and re-sample
52+
* traces for improved map matching results
53+
* @param roundaboutExits Whether or not to emit instructions at roundabout exits.
5454
* @param bannerInstructions Whether or not to return banner objects associated with
5555
* the `routeSteps`. Should be used in conjunction with `steps`.
56-
* @param voiceInstructions whether or not to return
57-
* marked-up text for voice guidance along the route.
58-
* @param waypoints Which input coordinates should be treated as waypoints.
56+
* @param voiceInstructions whether or not to return
57+
* marked-up text for voice guidance along the route.
58+
* @param voiceUnits voice units
59+
* @param waypoints Which input coordinates should be treated as waypoints.
5960
* @return the MapMatchingResponse in a Call wrapper
6061
* @since 2.0.0
6162
*/
@@ -77,5 +78,6 @@ Call<MapMatchingResponse> getCall(
7778
@Query("roundabout_exits") Boolean roundaboutExits,
7879
@Query("banner_instructions") Boolean bannerInstructions,
7980
@Query("voice_instructions") Boolean voiceInstructions,
81+
@Query("voice_units") String voiceUnits,
8082
@Query("waypoints") String waypoints);
8183
}

services-matching/src/main/java/com/mapbox/api/matching/v5/MapboxMapMatching.java

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.mapbox.api.matching.v5;
22

3-
import static com.sun.xml.internal.ws.spi.db.BindingContextFactory.LOGGER;
4-
53
import android.support.annotation.FloatRange;
64
import android.support.annotation.IntRange;
75
import android.support.annotation.NonNull;
@@ -27,21 +25,21 @@
2725
import com.mapbox.core.utils.MapboxUtils;
2826
import com.mapbox.core.utils.TextUtils;
2927
import com.mapbox.geojson.Point;
30-
31-
import okhttp3.ResponseBody;
32-
import retrofit2.Call;
33-
import retrofit2.Callback;
34-
import retrofit2.Converter;
35-
import retrofit2.Response;
28+
import com.sun.xml.internal.ws.spi.db.BindingContextFactory;
3629

3730
import java.io.IOException;
3831
import java.lang.annotation.Annotation;
39-
4032
import java.util.ArrayList;
4133
import java.util.List;
4234
import java.util.Locale;
4335
import java.util.logging.Level;
4436

37+
import okhttp3.ResponseBody;
38+
import retrofit2.Call;
39+
import retrofit2.Callback;
40+
import retrofit2.Converter;
41+
import retrofit2.Response;
42+
4543
/**
4644
* The Mapbox map matching interface (v5)
4745
* <p>
@@ -50,7 +48,7 @@
5048
* be displayed on a map or used for other analysis.
5149
*
5250
* @see <a href="https://www.mapbox.com/api-documentation/#map-matching">Map matching API
53-
* documentation</a>
51+
* documentation</a>
5452
* @since 2.0.0
5553
*/
5654
@AutoValue
@@ -88,6 +86,7 @@ protected Call<MapMatchingResponse> initializeCall() {
8886
roundaboutExits(),
8987
bannerInstructions(),
9088
voiceInstructions(),
89+
voiceUnits(),
9190
waypoints());
9291
}
9392

@@ -108,9 +107,9 @@ public Response<MapMatchingResponse> executeCall() throws IOException {
108107
}
109108

110109
return Response.success(response.body()
111-
.toBuilder()
112-
.matchings(generateRouteOptions(response))
113-
.build());
110+
.toBuilder()
111+
.matchings(generateRouteOptions(response))
112+
.build());
114113
}
115114

116115
/**
@@ -165,7 +164,9 @@ private void errorDidOccur(@Nullable Callback<MapMatchingResponse> callback,
165164
callback.onFailure(getCall(),
166165
new Throwable(errorConverter.convert(response.errorBody()).message()));
167166
} catch (IOException ioException) {
168-
LOGGER.log(Level.WARNING, "Failed to complete your request. ", ioException);
167+
BindingContextFactory.LOGGER.log(
168+
Level.WARNING, "Failed to complete your request. ", ioException
169+
);
169170
}
170171
}
171172

@@ -183,11 +184,7 @@ private List<MapMatchingMatching> generateRouteOptions(Response<MapMatchingRespo
183184
.user(user())
184185
.voiceInstructions(voiceInstructions())
185186
.bannerInstructions(bannerInstructions())
186-
//.continueStraight(continueStraight())
187-
//.bearings(bearings())
188-
//.alternatives(alternatives())
189-
//.exclude(exclude())
190-
//.voiceUnits(voiceUnits())
187+
.voiceUnits(voiceUnits())
191188
.requestUuid("mapmatching")
192189
.accessToken(accessToken())
193190
.baseUrl(baseUrl())
@@ -259,8 +256,10 @@ private static List<Point> formatCoordinates(String coordinates) {
259256
abstract Boolean voiceInstructions();
260257

261258
@Nullable
262-
abstract String waypoints();
259+
abstract String voiceUnits();
263260

261+
@Nullable
262+
abstract String waypoints();
264263

265264
@NonNull
266265
@Override
@@ -448,6 +447,16 @@ public Builder waypoints(@Nullable @IntRange(from = 0) Integer... waypoints) {
448447
*/
449448
public abstract Builder voiceInstructions(@Nullable Boolean voiceInstructions);
450449

450+
/**
451+
* Specify what unit you'd like voice and banner instructions to use.
452+
*
453+
* @param voiceUnits either Imperial (default) or Metric
454+
* @return this builder for chaining options together
455+
* @since 3.0.0
456+
*/
457+
public abstract Builder voiceUnits(
458+
@Nullable @DirectionsCriteria.VoiceUnitCriteria String voiceUnits
459+
);
451460

452461
/**
453462
* Setting this will determine whether to return steps and turn-by-turn instructions. Can be
@@ -473,7 +482,7 @@ public Builder waypoints(@Nullable @IntRange(from = 0) Integer... waypoints) {
473482
* or null which will result in no annotations being used
474483
* @return this builder for chaining options together
475484
* @see <a href="https://www.mapbox.com/api-documentation/#routeleg-object">RouteLeg object
476-
* documentation</a>
485+
* documentation</a>
477486
* @since 2.1.0
478487
*/
479488
public Builder annotations(@Nullable @AnnotationCriteria String... annotations) {
@@ -545,7 +554,7 @@ public Builder coordinate(@NonNull Point coordinate) {
545554
* written in when returned
546555
* @return this builder for chaining options together
547556
* @see <a href="https://www.mapbox.com/api-documentation/#instructions-languages">Supported
548-
* Languages</a>
557+
* Languages</a>
549558
* @since 3.0.0
550559
*/
551560
public Builder language(@Nullable Locale language) {
@@ -564,7 +573,7 @@ public Builder language(@Nullable Locale language) {
564573
* written in when returned
565574
* @return this builder for chaining options together
566575
* @see <a href="https://www.mapbox.com/api-documentation/#instructions-languages">Supported
567-
* Languages</a>
576+
* Languages</a>
568577
* @since 2.2.0
569578
*/
570579
public abstract Builder language(String language);

services-matching/src/test/java/com/mapbox/api/matching/v5/MapboxMapMatchingTest.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
package com.mapbox.api.matching.v5;
22

3-
import static org.hamcrest.CoreMatchers.containsString;
4-
import static org.hamcrest.junit.MatcherAssert.assertThat;
5-
6-
import com.mapbox.api.matching.v5.models.MapMatchingMatching;
3+
import com.mapbox.api.directions.v5.DirectionsCriteria;
74
import com.mapbox.api.matching.v5.models.MapMatchingResponse;
85
import com.mapbox.core.TestUtils;
96
import com.mapbox.core.exceptions.ServicesException;
10-
import com.mapbox.api.directions.v5.DirectionsCriteria;
117
import com.mapbox.geojson.Point;
128

139
import org.junit.After;
@@ -27,7 +23,9 @@
2723
import okhttp3.mockwebserver.RecordedRequest;
2824
import retrofit2.Response;
2925

26+
import static org.hamcrest.CoreMatchers.containsString;
3027
import static org.hamcrest.Matchers.startsWith;
28+
import static org.hamcrest.junit.MatcherAssert.assertThat;
3129
import static org.junit.Assert.assertNotNull;
3230
import static org.junit.Assert.assertTrue;
3331

@@ -447,6 +445,21 @@ public void sanityVoiceInstructions() throws Exception {
447445
.contains("voice_instructions=true"));
448446
}
449447

448+
@Test
449+
public void sanityVoiceUnits() throws Exception {
450+
MapboxMapMatching mapMatching = MapboxMapMatching.builder()
451+
.coordinate(Point.fromLngLat(2.0, 2.0))
452+
.coordinate(Point.fromLngLat(4.0, 4.0))
453+
.voiceInstructions(true)
454+
.voiceUnits(DirectionsCriteria.METRIC)
455+
.baseUrl("https://foobar.com")
456+
.accessToken(ACCESS_TOKEN)
457+
.build();
458+
assertNotNull(mapMatching);
459+
assertTrue(mapMatching.cloneCall().request().url().toString()
460+
.contains("voice_units=metric"));
461+
}
462+
450463
@Test
451464
public void sanityBannerInstructions() throws Exception {
452465
MapboxMapMatching mapMatching = MapboxMapMatching.builder()

0 commit comments

Comments
 (0)