Skip to content

Commit 49d27d6

Browse files
authored
added exit convenience method (#303)
* added convenience method for directions exit property
1 parent 707af0b commit 49d27d6

4 files changed

Lines changed: 60 additions & 2 deletions

File tree

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ directions-fixtures:
9191
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-122.416667,37.783333;-121.900000,37.333333?geometries=polyline6&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
9292
-o mapbox/libjava-services/src/test/fixtures/directions_v5_precision_6.json
9393

94+
directions-fixtures-exit-property:
95+
curl "https://api.mapbox.com/directions/v5/mapbox/driving/-77.02962040901184,38.90728142481329;-77.02808618545532,38.910111607145296?geometries=polyline&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
96+
-o mapbox/libjava-services/src/test/fixtures/directions_v5_exit_property.json
97+
9498
directions-traffic-fixtures:
9599
curl "https://api.mapbox.com/directions/v5/mapbox/driving-traffic/-122.416667,37.783333;-121.900000,37.333333?geometries=polyline&steps=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
96100
-o mapbox/libjava-services/src/test/fixtures/directions_v5_traffic.json

mapbox/libjava-services/src/main/java/com/mapbox/services/api/directions/v5/models/StepManeuver.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class StepManeuver {
2121
private String pronunciation;
2222
private String modifier;
2323
private String instruction;
24+
private Integer exit;
2425

2526
/**
2627
* @return double array of [longitude, latitude] for the snapped coordinate.
@@ -75,6 +76,22 @@ public String getType() {
7576
return type;
7677
}
7778

79+
/**
80+
* An optional integer indicating number of the exit to take.
81+
* If exit is undefined the destination is on the roundabout.
82+
* The property exists for the following type properties:
83+
*
84+
* else - indicates the number of intersections passed until the turn.
85+
* roundabout - traverse roundabout
86+
* rotary - a traffic circle
87+
*
88+
* @return String of an integer indicating number of the exit to take.
89+
* @since 2.0.0
90+
*/
91+
public Integer getExit() {
92+
return exit;
93+
}
94+
7895
/**
7996
* The pronunciation hint of the way name. Will be undefined if no pronunciation is hit.
8097
*
@@ -132,6 +149,7 @@ public String toString() {
132149
+ ", type='" + type + '\''
133150
+ ", pronunciation='" + pronunciation + '\''
134151
+ ", modifier='" + modifier + '\''
152+
+ ", exit=" + exit
135153
+ '}';
136154
}
137155
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"routes":[{"legs":[{"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[0],"location":[-77.029629,38.90728]},{"out":0,"location":[-77.029631,38.908575],"bearings":[0,90,180,270],"entry":[true,true,false,false],"in":2},{"out":0,"location":[-77.029621,38.908746],"bearings":[15,180,345],"entry":[true,false,false],"in":1}],"geometry":"oanlFdzcuMG?mF?M?M?SAQESIEEMKSY","maneuver":{"bearing_after":0,"location":[-77.029629,38.90728],"bearing_before":0,"type":"depart","instruction":"Head north on 13th Street Northwest"},"duration":17.6,"distance":215.8,"name":"13th Street Northwest","mode":"driving"},{"intersections":[{"out":0,"location":[-77.029315,38.909144],"bearings":[60,225,240],"entry":[true,false,false],"in":1},{"out":0,"location":[-77.028943,38.909474],"bearings":[15,45,195],"entry":[true,true,false],"in":2},{"out":0,"location":[-77.028904,38.909711],"bearings":[30,120,180,345],"entry":[true,false,false,true],"in":2}],"geometry":"cmnlFfxcuMEMCGEICEEEEGEEGEECMGGAMCE?SAGCECEEGGEIAEMe@W_AEU","maneuver":{"exit":2,"bearing_after":63,"type":"roundabout","modifier":"straight","bearing_before":43,"location":[-77.029315,38.909144],"instruction":"Enter the roundabout and take the 2nd exit onto Rhode Island Avenue Northwest"},"duration":10.9,"distance":162.8,"name":"Rhode Island Avenue Northwest","mode":"driving"},{"intersections":[{"in":0,"entry":[true],"bearings":[246],"location":[-77.028088,38.910114]}],"geometry":"esnlFppcuM","maneuver":{"bearing_after":0,"location":[-77.028088,38.910114],"bearing_before":66,"type":"arrive","instruction":"You have arrived at your destination"},"duration":0,"distance":0,"name":"Rhode Island Avenue Northwest","mode":"driving"}],"summary":"13th Street Northwest, Rhode Island Avenue Northwest","duration":28.5,"distance":378.6}],"geometry":"oanlFdzcuMcG?s@Gg@[g@_AYY[Mg@E[Us@kC","duration":28.5,"distance":378.6}],"waypoints":[{"name":"13th Street Northwest","location":[-77.029629,38.90728]},{"name":"Rhode Island Avenue Northwest","location":[-77.028088,38.910114]}],"code":"Ok"}

mapbox/libjava-services/src/test/java/com/mapbox/services/api/directions/v5/MapboxDirectionsTest.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.nio.file.Files;
2323
import java.nio.file.Paths;
2424
import java.util.ArrayList;
25+
import java.util.List;
2526
import java.util.Locale;
2627

2728
import okhttp3.HttpUrl;
@@ -42,7 +43,7 @@ public class MapboxDirectionsTest {
4243
public static final String DIRECTIONS_V5_FIXTURE = "src/test/fixtures/directions_v5.json";
4344
public static final String DIRECTIONS_V5_PRECISION6_FIXTURE = "src/test/fixtures/directions_v5_precision_6.json";
4445
public static final String DIRECTIONS_TRAFFIC_FIXTURE = "src/test/fixtures/directions_v5_traffic.json";
45-
46+
public static final String DIRECTIONS_EXIT_FIXTURE = "src/test/fixtures/directions_v5_exit_property.json";
4647
private static final double DELTA = 1E-10;
4748

4849
private MockWebServer server;
@@ -58,13 +59,18 @@ public void setUp() throws IOException {
5859

5960
@Override
6061
public MockResponse dispatch(RecordedRequest request) throws InterruptedException {
62+
6163
// Switch response on geometry parameter (only false supported, so nice and simple)
6264
String resource = DIRECTIONS_V5_FIXTURE;
6365
if (request.getPath().contains("geometries=polyline6")) {
6466
resource = DIRECTIONS_V5_PRECISION6_FIXTURE;
65-
} else if (request.getPath().contains("driving-traffic")) {
67+
}
68+
if (request.getPath().contains("driving-traffic")) {
6669
resource = DIRECTIONS_TRAFFIC_FIXTURE;
6770
}
71+
if (request.getPath().contains("-77.02962")) {
72+
resource = DIRECTIONS_EXIT_FIXTURE;
73+
}
6874

6975
try {
7076
String body = new String(Files.readAllBytes(Paths.get(resource)), Charset.forName("utf-8"));
@@ -347,8 +353,37 @@ public void testStepManeuver() throws ServicesException, IOException {
347353
assertEquals(maneuver.getType(), "depart");
348354
assertEquals(maneuver.getModifier(), "left");
349355
assertEquals(maneuver.getInstruction(), "Head west on Eddy Street");
356+
assertEquals(maneuver.getExit(), null);
350357
}
351358

359+
360+
@Test
361+
public void testStepManeuverForExit() throws ServicesException, IOException {
362+
List<Position> positionsExit = new ArrayList<>();
363+
positionsExit.add(Position.fromCoordinates(-77.02962040901184, 38.90728142481329));
364+
positionsExit.add(Position.fromCoordinates(-77.02808618545532, 38.910111607145296));
365+
366+
MapboxDirections client = new MapboxDirections.Builder()
367+
.setAccessToken("pk.XXX")
368+
.setCoordinates(positionsExit)
369+
.setProfile(DirectionsCriteria.PROFILE_DRIVING)
370+
.setBaseUrl(mockUrl.toString())
371+
.build();
372+
Response<DirectionsResponse> response = client.executeCall();
373+
374+
StepManeuver maneuver = response.body().getRoutes().get(0).getLegs().get(0).getSteps().get(1).getManeuver();
375+
assertEquals(maneuver.asPosition().getLongitude(), -77.029315, DELTA);
376+
assertEquals(maneuver.asPosition().getLatitude(), 38.909144, DELTA);
377+
assertEquals(maneuver.getBearingBefore(), 43.0, DELTA);
378+
assertEquals(maneuver.getBearingAfter(), 63.0, DELTA);
379+
assertEquals(maneuver.getType(), "roundabout");
380+
assertEquals(maneuver.getModifier(), "straight");
381+
assertEquals(maneuver.getInstruction(),
382+
"Enter the roundabout and take the 2nd exit onto Rhode Island Avenue Northwest");
383+
assertEquals(maneuver.getExit(), new Integer(2));
384+
}
385+
386+
352387
@Test
353388
public void testSetCoordinates() {
354389
ArrayList test = new ArrayList<>();

0 commit comments

Comments
 (0)