com.mapbox.api.directions.v5.DirectionsCriteria Java Examples

The following examples show how to use com.mapbox.api.directions.v5.DirectionsCriteria. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MapboxMatrixTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void destinationListSizeLimitCheckThatCallWorks() throws ServicesException, IOException {
  int total = 35;
  ArrayList<Point> positions = new ArrayList<>();
  for (int i = 0; i < total; i++) {
    positions.add(Point.fromLngLat(0.0, 0.0));
  }

  MapboxMatrix client = MapboxMatrix.builder()
      .accessToken(ACCESS_TOKEN)
      .profile(DirectionsCriteria.PROFILE_DRIVING)
      .coordinateListSizeLimit(50)
      .coordinates(positions)
      .build();

  Response<MatrixResponse> response = client.executeCall();
  assertFalse(response.isSuccessful());
  assertNull(response.body());
}
 
Example #2
Source File: MapboxMapMatchingTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void testCallForUrlLength_shortUrl() {
  MapboxMapMatching.Builder builder = MapboxMapMatching.builder()
    .profile(PROFILE_CYCLING)
    .steps(true)
    .coordinate(Point.fromLngLat(-122.42,37.78))
    .coordinate(Point.fromLngLat(-77.03,38.91))
    .voiceInstructions(true)
    .voiceUnits(DirectionsCriteria.IMPERIAL)
    .accessToken(ACCESS_TOKEN)
    .baseUrl(mockUrl.toString());
  addWaypoints(builder, 10);

  retrofit2.Call<MapMatchingResponse> call = builder.build().initializeCall();

  assertEquals("GET", call.request().method());
}
 
Example #3
Source File: MapboxMapMatchingTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void testCallForUrlLength_longUrl() {
  MapboxMapMatching.Builder builder = MapboxMapMatching.builder()
    .profile(PROFILE_CYCLING)
    .steps(true)
    .coordinate(Point.fromLngLat(-122.42,37.78))
    .coordinate(Point.fromLngLat(-77.03,38.91))
    .voiceInstructions(true)
    .voiceUnits(DirectionsCriteria.IMPERIAL)
    .accessToken(ACCESS_TOKEN)
    .baseUrl(mockUrl.toString());
  addWaypoints(builder, 400);

  retrofit2.Call<MapMatchingResponse> call = builder.build().initializeCall();

  assertEquals("POST", call.request().method());
}
 
Example #4
Source File: MapboxMapMatchingTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void testPostIsUsed() {
  MapboxMapMatching.Builder builder = MapboxMapMatching.builder()
    .profile(PROFILE_CYCLING)
    .steps(true)
    .coordinate(Point.fromLngLat(-122.42,37.78))
    .coordinate(Point.fromLngLat(-77.03,38.91))
    .voiceInstructions(true)
    .voiceUnits(DirectionsCriteria.IMPERIAL)
    .accessToken(ACCESS_TOKEN)
    .baseUrl(mockUrl.toString())
    .post();

  retrofit2.Call<MapMatchingResponse> call = builder.build().initializeCall();

  assertEquals("POST", call.request().method());
}
 
Example #5
Source File: MapboxMapMatchingTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void testGetIsUsed() {
  MapboxMapMatching.Builder builder = MapboxMapMatching.builder()
    .profile(PROFILE_CYCLING)
    .steps(true)
    .coordinate(Point.fromLngLat(-122.42,37.78))
    .coordinate(Point.fromLngLat(-77.03,38.91))
    .voiceInstructions(true)
    .voiceUnits(DirectionsCriteria.IMPERIAL)
    .accessToken(ACCESS_TOKEN)
    .baseUrl(mockUrl.toString())
    .get();

  retrofit2.Call<MapMatchingResponse> call = builder.build().initializeCall();

  assertEquals("GET", call.request().method());
}
 
Example #6
Source File: MapMatchingRouteOptionsTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void sanity() throws Exception {
  List<Point> pointList = new ArrayList<>();
  pointList.add(Point.fromLngLat(1.0, 2.0));
  pointList.add(Point.fromLngLat(3.0, 4.0));
  RouteOptions routeOptions = RouteOptions.builder()
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
    .baseUrl(mockUrl.toString())
    .profile("hello")
    .user("user")
    .coordinates(pointList)
    .accessToken(ACCESS_TOKEN)
    .requestUuid("uuid")
    .build();
  assertNotNull(routeOptions);
  assertEquals("hello", routeOptions.profile());
}
 
Example #7
Source File: MapMatchingRouteOptionsTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void mapMatchingRequestResult_doesContainTheOriginalRequestData() throws Exception {
  Response<MapMatchingResponse> response = MapboxMapMatching.builder()
    .coordinates(coordinates)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
    .baseUrl(mockUrl.toString())
    .accessToken(ACCESS_TOKEN)
    .profile(DirectionsCriteria.PROFILE_WALKING)
    .language(Locale.CANADA).build().executeCall();
  MapMatchingMatching matching = response.body().matchings().get(0);

  assertEquals(Locale.CANADA.getLanguage(), matching.routeOptions().language());
  assertEquals(DirectionsCriteria.PROFILE_WALKING, matching.routeOptions().profile());
  assertEquals(Constants.MAPBOX_USER, matching.routeOptions().user());

  // Never set values
  assertNull(matching.routeOptions().annotations());
  assertNull(matching.routeOptions().bearingsList());
}
 
Example #8
Source File: MapMatchingRouteOptionsTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void mapMatchingRequestResult_doesContainOverview() throws Exception {
  Response<MapMatchingResponse> response = MapboxMapMatching.builder()
    .coordinates(coordinates)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
    .baseUrl(mockUrl.toString())
    .accessToken(ACCESS_TOKEN)
    .profile(DirectionsCriteria.PROFILE_WALKING)
    .language(Locale.CANADA)
    .overview(DirectionsCriteria.OVERVIEW_SIMPLIFIED)
    .build()
    .executeCall();
  MapMatchingMatching matching = response.body().matchings().get(0);

  assertEquals(DirectionsCriteria.OVERVIEW_SIMPLIFIED, matching.routeOptions().overview());
}
 
Example #9
Source File: MapboxMatrixTest.java    From mapbox-java with MIT License 6 votes vote down vote up
/**
 * Test the most basic request (default response format)
 */
@Test
public void testCallSanity() throws ServicesException, IOException {
  MapboxMatrix client = MapboxMatrix.builder()
    .accessToken(ACCESS_TOKEN)
    .profile(DirectionsCriteria.PROFILE_DRIVING)
    .coordinates(positions)
    .baseUrl(mockUrl.toString())
    .build();
  Response<MatrixResponse> response = client.executeCall();
  assertEquals(200, response.code());

  // Check the response body
  assertNotNull(response.body());
  assertEquals(3, response.body().destinations().size());
  assertNotNull(response.body().destinations().get(0).name());
  assertEquals(3, response.body().durations().size());
}
 
Example #10
Source File: MapboxMatrixTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void validCoordinatesTotal() throws ServicesException {
  int total = 26;
  ArrayList<Point> positions = new ArrayList<>();
  for (int i = 0; i < total; i++) {
    // Fake too many positions
    positions.add(Point.fromLngLat(0.0, 0.0));
  }

  thrown.expect(ServicesException.class);
  thrown.expectMessage(startsWith(
      "A maximum of 25 coordinates is the default " +
          " allowed for this API. If your Mapbox account has been enabled by the" +
          " Mapbox team to make a request with more than 25 coordinates, please use" +
          " the builder's coordinateListSizeLimit() method and pass through your account" +
          "-specific maximum."
  ));
  MapboxMatrix.builder()
    .accessToken(ACCESS_TOKEN)
    .profile(DirectionsCriteria.PROFILE_DRIVING)
    .coordinates(positions)
    .build();
}
 
Example #11
Source File: MapboxMatrixTest.java    From mapbox-java with MIT License 6 votes vote down vote up
@Test
public void annotationsAndApproaches() throws ServicesException, IOException {
  MapboxMatrix client = MapboxMatrix.builder()
    .accessToken(ACCESS_TOKEN)
    .profile(DirectionsCriteria.PROFILE_WALKING)
    .coordinates(positions)
    .addAnnotations(ANNOTATION_DISTANCE, ANNOTATION_DURATION)
    .addApproaches(APPROACH_CURB, APPROACH_CURB, APPROACH_CURB)
    .sources(0,2)
    .baseUrl(mockUrl.toString())
    .build();

  Response<MatrixResponse> response = client.executeCall();
  assertEquals(200, response.code());
  assertEquals(1, response.body().sources().size());
  assertEquals(1, response.body().distances().size());
  assertEquals(1, response.body().durations().size());
  assertEquals(-122.461997, response.body().sources().get(0).location().longitude(), DELTA);
  assertEquals(-122.420019, response.body().destinations().get(0).location().longitude(),  DELTA);
  assertEquals(19711.7, response.body().durations().get(0)[2], DELTA);
  assertEquals(27192.3, response.body().distances().get(0)[2], DELTA);
  assertEquals("McAllister Street", response.body().destinations().get(0).name());
}
 
Example #12
Source File: RouteUtilsTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void isValidRouteProfile_returnsTrueWithDrivingTrafficProfile() throws Exception {
  String routeProfileDrivingTraffic = DirectionsCriteria.PROFILE_DRIVING_TRAFFIC;
  RouteUtils routeUtils = new RouteUtils();

  boolean isValidProfile = routeUtils.isValidRouteProfile(routeProfileDrivingTraffic);

  assertTrue(isValidProfile);
}
 
Example #13
Source File: NavigationMapRouteActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
public void requestDirectionsRoute(Point origin, Point destination) {
  MapboxDirections directions = MapboxDirections.builder()
    .origin(origin)
    .destination(destination)
    .accessToken(Mapbox.getAccessToken())
    .profile(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC)
    .overview(DirectionsCriteria.OVERVIEW_FULL)
    .annotations(DirectionsCriteria.ANNOTATION_CONGESTION)
    .alternatives(true)
    .steps(true)
    .build();

  directions.enqueueCall(this);
}
 
Example #14
Source File: MapboxMapMatchingTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@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"));
}
 
Example #15
Source File: MapboxMapMatchingTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void annotations_doesShowInUrlCorrectly() throws Exception {
  MapboxMapMatching mapMatching = MapboxMapMatching.builder()
    .coordinate(Point.fromLngLat(2.1234, 3.3456))
    .coordinate(Point.fromLngLat(90.10293, 7.10293))
    .coordinate(Point.fromLngLat(100.10203, 84.039))
    .baseUrl("https://foobar.com")
    .accessToken(ACCESS_TOKEN)
    .annotations(
      DirectionsCriteria.ANNOTATION_DISTANCE,
      DirectionsCriteria.ANNOTATION_CONGESTION
    ).build();
  assertEquals("distance,congestion",
    mapMatching.cloneCall().request().url().queryParameter("annotations"));
}
 
Example #16
Source File: MapboxMapMatchingTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void overview_doesShowInUrlCorrectly() throws Exception {
  MapboxMapMatching mapMatching = MapboxMapMatching.builder()
    .coordinate(Point.fromLngLat(2.1234, 3.3456))
    .coordinate(Point.fromLngLat(90.10293, 7.10293))
    .coordinate(Point.fromLngLat(100.10203, 84.039))
    .baseUrl("https://foobar.com")
    .accessToken(ACCESS_TOKEN)
    .overview(DirectionsCriteria.OVERVIEW_FULL)
    .build();
  assertTrue(mapMatching.cloneCall().request().url().toString()
    .contains("overview=full"));
}
 
Example #17
Source File: MapboxMapMatchingTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void geometries_doesShowInUrlCorrectly() throws Exception {
  MapboxMapMatching mapMatching = MapboxMapMatching.builder()
    .coordinate(Point.fromLngLat(2.1234, 3.3456))
    .coordinate(Point.fromLngLat(90.10293, 7.10293))
    .coordinate(Point.fromLngLat(100.10203, 84.039))
    .baseUrl("https://foobar.com")
    .accessToken(ACCESS_TOKEN)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE)
    .build();
  assertTrue(mapMatching.cloneCall().request().url().toString()
    .contains("geometries=polyline"));
}
 
Example #18
Source File: MapboxMapMatching.java    From mapbox-java with MIT License 5 votes vote down vote up
/**
 * Build a new {@link MapboxMapMatching} object with the initial values set for
 * {@link #baseUrl()}, {@link #profile()}, {@link #geometries()}, and {@link #user()}.
 *
 * @return a {@link Builder} object for creating this object
 * @since 3.0.0
 */
public static Builder builder() {
  return new AutoValue_MapboxMapMatching.Builder()
    .baseUrl(Constants.BASE_API_URL)
    .profile(DirectionsCriteria.PROFILE_DRIVING)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
    .user(DirectionsCriteria.PROFILE_DEFAULT_USER);
}
 
Example #19
Source File: MapboxOptimization.java    From mapbox-java with MIT License 5 votes vote down vote up
/**
 * Build a new {@link MapboxOptimization} object with the initial values set for
 * {@link #baseUrl()}, {@link #profile()}, {@link #user()}, and {@link #geometries()}.
 *
 * @return a {@link Builder} object for creating this object
 * @since 3.0.0
 */
public static Builder builder() {
  return new AutoValue_MapboxOptimization.Builder()
    .baseUrl(Constants.BASE_API_URL)
    .profile(DirectionsCriteria.PROFILE_DRIVING)
    .user(DirectionsCriteria.PROFILE_DEFAULT_USER)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6);
}
 
Example #20
Source File: NavigationRoute.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
static Builder builder(Context context, LocaleUtils localeUtils) {
  return new Builder()
    .annotations(DirectionsCriteria.ANNOTATION_CONGESTION, DirectionsCriteria.ANNOTATION_DISTANCE)
    .language(context, localeUtils)
    .voiceUnits(context, localeUtils)
    .profile(DirectionsCriteria.PROFILE_DRIVING_TRAFFIC);
}
 
Example #21
Source File: MapboxNavigationActivity.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
private void extractConfiguration(NavigationViewOptions.Builder options,
                                  MapboxNavigationOptions.Builder navigationOptions) {
  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
  options.shouldSimulateRoute(preferences
    .getBoolean(NavigationConstants.NAVIGATION_VIEW_SIMULATE_ROUTE, false));
  options.directionsProfile(preferences
    .getString(NavigationConstants.NAVIGATION_VIEW_ROUTE_PROFILE_KEY, DirectionsCriteria.PROFILE_DRIVING_TRAFFIC));
  navigationOptions.enableOffRouteDetection(preferences
    .getBoolean(NavigationConstants.NAVIGATION_VIEW_OFF_ROUTE_ENABLED_KEY, true));
  navigationOptions.snapToRoute(preferences
    .getBoolean(NavigationConstants.NAVIGATION_VIEW_SNAP_ENABLED_KEY, true));
}
 
Example #22
Source File: NavigationRoute.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
/**
 * This uses the provided parameters set using the {@link Builder} and adds the required
 * settings for navigation to work correctly.
 *
 * @return a new instance of Navigation Route
 * @since 0.5.0
 */
public NavigationRoute build() {
  // Set the default values which the user cannot alter.
  directionsBuilder
    .steps(true)
    .continueStraight(true)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
    .overview(DirectionsCriteria.OVERVIEW_FULL)
    .voiceInstructions(true)
    .bannerInstructions(true)
    .roundaboutExits(true);
  return new NavigationRoute(directionsBuilder.build());
}
 
Example #23
Source File: LocaleUtils.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
/**
 * Returns the unit type for the specified locale. Try to avoid using this unnecessarily because
 * all methods consuming unit type are able to handle the NONE_SPECIFIED type
 *
 * @param locale for which to return the default unit type
 * @return unit type for specified locale
 */
@DirectionsCriteria.VoiceUnitCriteria
public String getUnitTypeForLocale(@NonNull Locale locale) {
  switch (locale.getCountry()) {
    case "US": // US
    case "LR": // Liberia
    case "MM": // Burma
      return DirectionsCriteria.IMPERIAL;
    default:
      return DirectionsCriteria.METRIC;
  }
}
 
Example #24
Source File: MapMatchingRouteOptionsTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void mapMatchingRequestResult_doesContainBaseUrl() throws Exception {
  Response<MapMatchingResponse> response = MapboxMapMatching.builder()
    .coordinates(coordinates)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
    .baseUrl(mockUrl.toString())
    .accessToken(ACCESS_TOKEN)
    .profile(DirectionsCriteria.PROFILE_WALKING)
    .language(Locale.CANADA)
    .build().executeCall();
  MapMatchingMatching matching = response.body().matchings().get(0);

  assertEquals(mockUrl.toString(), matching.routeOptions().baseUrl());
}
 
Example #25
Source File: MapMatchingRouteOptionsTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void mapMatchingRequestResult_doesContainRoundaboutExits() throws Exception {
  Response<MapMatchingResponse> response = MapboxMapMatching.builder()
    .coordinates(coordinates)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
    .baseUrl(mockUrl.toString())
    .accessToken(ACCESS_TOKEN)
    .profile(DirectionsCriteria.PROFILE_WALKING)
    .language(Locale.CANADA)
    .roundaboutExits(true)
    .build().executeCall();
  MapMatchingMatching matching = response.body().matchings().get(0);

  assertEquals(true, matching.routeOptions().roundaboutExits());
}
 
Example #26
Source File: MapMatchingRouteOptionsTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void mapMatchingRequestResult_doesContainSteps() throws Exception {
  Response<MapMatchingResponse> response = MapboxMapMatching.builder()
    .coordinates(coordinates)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
    .baseUrl(mockUrl.toString())
    .accessToken(ACCESS_TOKEN)
    .profile(DirectionsCriteria.PROFILE_WALKING)
    .language(Locale.CANADA)
    .steps(true)
    .build().executeCall();
  MapMatchingMatching matching = response.body().matchings().get(0);

  assertEquals(true, matching.routeOptions().steps());
}
 
Example #27
Source File: MapMatchingRouteOptionsTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void mapMatchingRequestResult_doesContainGeometries() throws Exception {
  Response<MapMatchingResponse> response = MapboxMapMatching.builder()
    .coordinates(coordinates)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE6)
    .baseUrl(mockUrl.toString())
    .accessToken(ACCESS_TOKEN)
    .profile(DirectionsCriteria.PROFILE_WALKING)
    .language(Locale.CANADA)
    .geometries(DirectionsCriteria.GEOMETRY_POLYLINE)
    .build().executeCall();
  MapMatchingMatching matching = response.body().matchings().get(0);

  assertEquals(DirectionsCriteria.GEOMETRY_POLYLINE, matching.routeOptions().geometries());
}
 
Example #28
Source File: NavigationRouteTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void changingDefaultValueToCustomWorksProperly() throws Exception {
  NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
    .accessToken(ACCESS_TOKEN)
    .origin(Point.fromLngLat(1.0, 2.0))
    .destination(Point.fromLngLat(1.0, 5.0))
    .profile(DirectionsCriteria.PROFILE_CYCLING)
    .build();

  assertThat(navigationRoute.getCall().request().url().toString(),
    containsString("/cycling/"));
}
 
Example #29
Source File: NavigationRouteTest.java    From graphhopper-navigation-android with MIT License 5 votes vote down vote up
@Test
public void addApproachesIncludedInRequest() {
  NavigationRoute navigationRoute = NavigationRoute.builder(context, localeUtils)
    .accessToken(ACCESS_TOKEN)
    .origin(Point.fromLngLat(1.0, 2.0))
    .destination(Point.fromLngLat(1.0, 5.0))
    .profile(DirectionsCriteria.PROFILE_CYCLING)
    .addApproaches(DirectionsCriteria.APPROACH_CURB, DirectionsCriteria.APPROACH_UNRESTRICTED)
    .build();

  assertThat(navigationRoute.getCall().request().url().toString(),
    containsString("curb"));
}
 
Example #30
Source File: MapboxMatrixTest.java    From mapbox-java with MIT License 5 votes vote down vote up
@Test
public void validCoordinates() throws ServicesException {
  thrown.expect(ServicesException.class);
  thrown.expectMessage(
    startsWith("At least two coordinates must be provided with your API request."));
  MapboxMatrix.builder()
    .accessToken(ACCESS_TOKEN)
    .profile(DirectionsCriteria.PROFILE_DRIVING)
    .build();
}