Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -77,5 +78,6 @@ Call<MapMatchingResponse> 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);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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)
* <p>
Expand All @@ -50,7 +48,7 @@
* be displayed on a map or used for other analysis.
*
* @see <a href="https://www.mapbox.com/api-documentation/#map-matching">Map matching API
* documentation</a>
* documentation</a>
* @since 2.0.0
*/
@AutoValue
Expand Down Expand Up @@ -88,6 +86,7 @@ protected Call<MapMatchingResponse> initializeCall() {
roundaboutExits(),
bannerInstructions(),
voiceInstructions(),
voiceUnits(),
waypoints());
}

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

return Response.success(response.body()
.toBuilder()
.matchings(generateRouteOptions(response))
.build());
.toBuilder()
.matchings(generateRouteOptions(response))
.build());
}

/**
Expand Down Expand Up @@ -165,7 +164,9 @@ private void errorDidOccur(@Nullable Callback<MapMatchingResponse> 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
);
}
}

Expand All @@ -183,11 +184,7 @@ private List<MapMatchingMatching> generateRouteOptions(Response<MapMatchingRespo
.user(user())
.voiceInstructions(voiceInstructions())
.bannerInstructions(bannerInstructions())
//.continueStraight(continueStraight())
//.bearings(bearings())
//.alternatives(alternatives())
//.exclude(exclude())
//.voiceUnits(voiceUnits())
.voiceUnits(voiceUnits())
.requestUuid("mapmatching")
.accessToken(accessToken())
.baseUrl(baseUrl())
Expand Down Expand Up @@ -259,8 +256,10 @@ private static List<Point> formatCoordinates(String coordinates) {
abstract Boolean voiceInstructions();

@Nullable
abstract String waypoints();
abstract String voiceUnits();

@Nullable
abstract String waypoints();

@NonNull
@Override
Expand Down Expand Up @@ -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
Expand All @@ -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 <a href="https://www.mapbox.com/api-documentation/#routeleg-object">RouteLeg object
* documentation</a>
* documentation</a>
* @since 2.1.0
*/
public Builder annotations(@Nullable @AnnotationCriteria String... annotations) {
Expand Down Expand Up @@ -545,7 +554,7 @@ public Builder coordinate(@NonNull Point coordinate) {
* written in when returned
* @return this builder for chaining options together
* @see <a href="https://www.mapbox.com/api-documentation/#instructions-languages">Supported
* Languages</a>
* Languages</a>
* @since 3.0.0
*/
public Builder language(@Nullable Locale language) {
Expand All @@ -564,7 +573,7 @@ public Builder language(@Nullable Locale language) {
* written in when returned
* @return this builder for chaining options together
* @see <a href="https://www.mapbox.com/api-documentation/#instructions-languages">Supported
* Languages</a>
* Languages</a>
* @since 2.2.0
*/
public abstract Builder language(String language);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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()
Expand Down