diff --git a/services-matching/src/main/java/com/mapbox/api/matching/v5/MapMatchingService.java b/services-matching/src/main/java/com/mapbox/api/matching/v5/MapMatchingService.java index 8c94e8aeb..cb2974440 100644 --- a/services-matching/src/main/java/com/mapbox/api/matching/v5/MapMatchingService.java +++ b/services-matching/src/main/java/com/mapbox/api/matching/v5/MapMatchingService.java @@ -19,43 +19,44 @@ public interface MapMatchingService { * Constructs the html call using the information passed in through the * {@link MapboxMapMatching.Builder}. * - * @param userAgent user agent - * @param user user - * @param profile directions profile ID; either mapbox/driving, mapbox/walking, - * or mapbox/cycling - * @param coordinates inaccurate traces from a GPS unit or a phone - * @param accessToken Mapbox access token - * @param geometries format of the returned geometry. Allowed values are: geojson - * (as LineString), polyline with precision 5, polyline6. The default - * value is polyline - * @param radiuses a list of integers in meters indicating the assumed precision of - * the used tracking device. There must be as many radiuses as there - * are coordinates in the request, each separated by ;. Values can be - * a number between 0 and 30. Use higher numbers (20-30) for noisy - * traces and lower numbers (1-10) for clean traces. The default value - * is 5 - * @param steps whether to return steps and turn-by-turn instructions. Can be true - * or false. The default is false - * @param overview type of returned overview geometry. Can be full (the most detailed - * geometry available), simplified (a simplified version of the full - * geometry), or false (no overview geometry). The default is simplified - * @param timestamps timestamps corresponding to each coordinate provided in the request; - * must be numbers in Unix time (seconds since the Unix epoch). There - * must be as many timestamps as there are coordinates in the request, - * each separated by {@code ;} - * @param annotations whether or not to return additional metadata for each coordinate - * along the match geometry. Can be one or all of 'duration', 'distance', - * or 'nodes', each separated by ,. See the response object for more - * details on what it is included with annotations - * @param language language of returned turn-by-turn text instructions - * @param tidy whether or not to transparently remove clusters and re-sample traces for - * improved map matching results - * @param roundaboutExits Whether or not to emit instructions at roundabout exits. + * @param userAgent user agent + * @param user user + * @param profile directions profile ID; either mapbox/driving, mapbox/walking, + * or mapbox/cycling + * @param coordinates inaccurate traces from a GPS unit or a phone + * @param accessToken Mapbox access token + * @param geometries format of the returned geometry. Allowed values are: geojson + * (as LineString), polyline with precision 5, polyline6. The default + * value is polyline + * @param radiuses a list of integers in meters indicating the assumed precision of + * the used tracking device. There must be as many radiuses as there + * are coordinates in the request, each separated by ;. Values can be + * a number between 0 and 30. Use higher numbers (20-30) for noisy + * traces and lower numbers (1-10) for clean traces. The default value + * is 5 + * @param steps whether to return steps and turn-by-turn instructions. Can be true + * or false. The default is false + * @param overview type of returned overview geometry. Can be full (the most detailed + * geometry available), simplified (a simplified version of the full + * geometry), or false (no overview geometry). The default is simplified + * @param timestamps timestamps corresponding to each coordinate provided in the request; + * must be numbers in Unix time (seconds since the Unix epoch). There + * must be as many timestamps as there are coordinates in the request, + * each separated by {@code ;} + * @param annotations whether or not to return additional metadata for each coordinate + * along the match geometry. Can be one or all of 'duration', + * 'distance', or 'nodes', each separated by ,. See the response + * object for more details on what it is included with annotations + * @param language language of returned turn-by-turn text instructions + * @param tidy whether or not to transparently remove clusters and re-sample + * traces for improved map matching results + * @param roundaboutExits Whether or not to emit instructions at roundabout exits. * @param bannerInstructions Whether or not to return banner objects associated with * the `routeSteps`. Should be used in conjunction with `steps`. - * @param voiceInstructions whether or not to return - * marked-up text for voice guidance along the route. - * @param waypoints Which input coordinates should be treated as waypoints. + * @param voiceInstructions whether or not to return + * marked-up text for voice guidance along the route. + * @param voiceUnits voice units + * @param waypoints Which input coordinates should be treated as waypoints. * @return the MapMatchingResponse in a Call wrapper * @since 2.0.0 */ @@ -77,5 +78,6 @@ Call getCall( @Query("roundabout_exits") Boolean roundaboutExits, @Query("banner_instructions") Boolean bannerInstructions, @Query("voice_instructions") Boolean voiceInstructions, + @Query("voice_units") String voiceUnits, @Query("waypoints") String waypoints); } diff --git a/services-matching/src/main/java/com/mapbox/api/matching/v5/MapboxMapMatching.java b/services-matching/src/main/java/com/mapbox/api/matching/v5/MapboxMapMatching.java index 45973996c..52d58d9ee 100644 --- a/services-matching/src/main/java/com/mapbox/api/matching/v5/MapboxMapMatching.java +++ b/services-matching/src/main/java/com/mapbox/api/matching/v5/MapboxMapMatching.java @@ -1,7 +1,5 @@ package com.mapbox.api.matching.v5; -import static com.sun.xml.internal.ws.spi.db.BindingContextFactory.LOGGER; - import android.support.annotation.FloatRange; import android.support.annotation.IntRange; import android.support.annotation.NonNull; @@ -27,21 +25,21 @@ import com.mapbox.core.utils.MapboxUtils; import com.mapbox.core.utils.TextUtils; import com.mapbox.geojson.Point; - -import okhttp3.ResponseBody; -import retrofit2.Call; -import retrofit2.Callback; -import retrofit2.Converter; -import retrofit2.Response; +import com.sun.xml.internal.ws.spi.db.BindingContextFactory; import java.io.IOException; import java.lang.annotation.Annotation; - import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.logging.Level; +import okhttp3.ResponseBody; +import retrofit2.Call; +import retrofit2.Callback; +import retrofit2.Converter; +import retrofit2.Response; + /** * The Mapbox map matching interface (v5) *

@@ -50,7 +48,7 @@ * be displayed on a map or used for other analysis. * * @see Map matching API - * documentation + * documentation * @since 2.0.0 */ @AutoValue @@ -88,6 +86,7 @@ protected Call initializeCall() { roundaboutExits(), bannerInstructions(), voiceInstructions(), + voiceUnits(), waypoints()); } @@ -108,9 +107,9 @@ public Response executeCall() throws IOException { } return Response.success(response.body() - .toBuilder() - .matchings(generateRouteOptions(response)) - .build()); + .toBuilder() + .matchings(generateRouteOptions(response)) + .build()); } /** @@ -165,7 +164,9 @@ private void errorDidOccur(@Nullable Callback callback, callback.onFailure(getCall(), new Throwable(errorConverter.convert(response.errorBody()).message())); } catch (IOException ioException) { - LOGGER.log(Level.WARNING, "Failed to complete your request. ", ioException); + BindingContextFactory.LOGGER.log( + Level.WARNING, "Failed to complete your request. ", ioException + ); } } @@ -183,11 +184,7 @@ private List generateRouteOptions(Response formatCoordinates(String coordinates) { abstract Boolean voiceInstructions(); @Nullable - abstract String waypoints(); + abstract String voiceUnits(); + @Nullable + abstract String waypoints(); @NonNull @Override @@ -448,6 +447,16 @@ public Builder waypoints(@Nullable @IntRange(from = 0) Integer... waypoints) { */ public abstract Builder voiceInstructions(@Nullable Boolean voiceInstructions); + /** + * Specify what unit you'd like voice and banner instructions to use. + * + * @param voiceUnits either Imperial (default) or Metric + * @return this builder for chaining options together + * @since 3.0.0 + */ + public abstract Builder voiceUnits( + @Nullable @DirectionsCriteria.VoiceUnitCriteria String voiceUnits + ); /** * 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) { * or null which will result in no annotations being used * @return this builder for chaining options together * @see RouteLeg object - * documentation + * documentation * @since 2.1.0 */ public Builder annotations(@Nullable @AnnotationCriteria String... annotations) { @@ -545,7 +554,7 @@ public Builder coordinate(@NonNull Point coordinate) { * written in when returned * @return this builder for chaining options together * @see Supported - * Languages + * Languages * @since 3.0.0 */ public Builder language(@Nullable Locale language) { @@ -564,7 +573,7 @@ public Builder language(@Nullable Locale language) { * written in when returned * @return this builder for chaining options together * @see Supported - * Languages + * Languages * @since 2.2.0 */ public abstract Builder language(String language); diff --git a/services-matching/src/test/java/com/mapbox/api/matching/v5/MapboxMapMatchingTest.java b/services-matching/src/test/java/com/mapbox/api/matching/v5/MapboxMapMatchingTest.java index e507a41e2..4d7f25924 100644 --- a/services-matching/src/test/java/com/mapbox/api/matching/v5/MapboxMapMatchingTest.java +++ b/services-matching/src/test/java/com/mapbox/api/matching/v5/MapboxMapMatchingTest.java @@ -1,13 +1,9 @@ package com.mapbox.api.matching.v5; -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.junit.MatcherAssert.assertThat; - -import com.mapbox.api.matching.v5.models.MapMatchingMatching; +import com.mapbox.api.directions.v5.DirectionsCriteria; import com.mapbox.api.matching.v5.models.MapMatchingResponse; import com.mapbox.core.TestUtils; import com.mapbox.core.exceptions.ServicesException; -import com.mapbox.api.directions.v5.DirectionsCriteria; import com.mapbox.geojson.Point; import org.junit.After; @@ -27,7 +23,9 @@ import okhttp3.mockwebserver.RecordedRequest; import retrofit2.Response; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.startsWith; +import static org.hamcrest.junit.MatcherAssert.assertThat; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; @@ -447,6 +445,21 @@ public void sanityVoiceInstructions() throws Exception { .contains("voice_instructions=true")); } + @Test + public void sanityVoiceUnits() throws Exception { + MapboxMapMatching mapMatching = MapboxMapMatching.builder() + .coordinate(Point.fromLngLat(2.0, 2.0)) + .coordinate(Point.fromLngLat(4.0, 4.0)) + .voiceInstructions(true) + .voiceUnits(DirectionsCriteria.METRIC) + .baseUrl("https://foobar.com") + .accessToken(ACCESS_TOKEN) + .build(); + assertNotNull(mapMatching); + assertTrue(mapMatching.cloneCall().request().url().toString() + .contains("voice_units=metric")); + } + @Test public void sanityBannerInstructions() throws Exception { MapboxMapMatching mapMatching = MapboxMapMatching.builder()