Skip to content

Commit 2ea82fb

Browse files
authored
Add voiceLanguage to MapMatchingMatching (#847)
1 parent 4d180b6 commit 2ea82fb

10 files changed

Lines changed: 100 additions & 6 deletions

File tree

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ mapmatching-fixtures:
150150
curl "https://api.mapbox.com/matching/v5/mapbox/driving/2.344003915786743,48.85805170891599;2.346750497817993,48.85727523615161;2.348681688308716,48.85936462637049;2.349550724029541,48.86084691113991;2.349550724029541,48.8608892614883;2.349625825881958,48.86102337068847;2.34982967376709,48.86125629633996?steps=true&tidy=true&waypoints=0;6&waypoint_names=Home;Work&banner_instructions=true&access_token=$(MAPBOX_ACCESS_TOKEN)" \
151151
-o services-matching/src/test/resources/mapmatching_v5_waypoint_names.json
152152

153+
# MapMatching with valid voiceLanguage
154+
curl "https://api.mapbox.com/matching/v5/mapbox/driving/$(MAP_MATCHING_COORDINATES)?steps=true&overview=full&geometries=polyline6&roundabout_exits=true&voice_instructions=true&language=en&access_token=$(MAPBOX_ACCESS_TOKEN)" \
155+
-o services-matching/src/test/resources/map_matching_v5_voice_language.json
156+
157+
# MapMatching with invalid voiceLanguage
158+
curl "https://api.mapbox.com/matching/v5/mapbox/driving/$(MAP_MATCHING_COORDINATES)?steps=true&overview=full&geometries=polyline6&roundabout_exits=true&voice_instructions=true&language=he&access_token=$(MAPBOX_ACCESS_TOKEN)" \
159+
-o services-matching/src/test/resources/map_matching_v5_invalid_voice_language.json
160+
153161
optimization-fixtures:
154162
# request an optimized car trip with no additional options
155163
curl "https://api.mapbox.com/optimized-trips/v1/mapbox/driving/-122.42,37.78;-122.45,37.91;-122.48,37.73?access_token=$(MAPBOX_ACCESS_TOKEN)" \

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.google.gson.TypeAdapter;
99
import com.google.gson.annotations.SerializedName;
1010
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
11+
import com.mapbox.api.directions.v5.MapboxDirections;
1112
import com.mapbox.geojson.BoundingBox;
1213
import com.mapbox.geojson.Geometry;
1314
import com.mapbox.geojson.Point;
@@ -126,7 +127,8 @@ public static DirectionsRoute fromJson(String json) {
126127

127128
/**
128129
* String of the language to be used for voice instructions. Defaults to en, and
129-
* can be any accepted instruction language.
130+
* can be any accepted instruction language. Will be <tt>null</tt> when the language provided
131+
* via {@link MapboxDirections#language()} is not compatible with API Voice.
130132
*
131133
* @return String compatible with voice instructions, null otherwise
132134
* @since 3.1.0

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

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package com.mapbox.api.matching.v5.models;
22

33
import android.support.annotation.Nullable;
4+
45
import com.google.auto.value.AutoValue;
56
import com.google.gson.Gson;
67
import com.google.gson.TypeAdapter;
78
import com.google.gson.annotations.SerializedName;
8-
import com.mapbox.api.directions.v5.models.RouteLeg;
99
import com.mapbox.api.directions.v5.models.DirectionsRoute;
10+
import com.mapbox.api.directions.v5.models.RouteLeg;
1011
import com.mapbox.api.directions.v5.models.RouteOptions;
1112

1213
import java.io.Serializable;
@@ -102,6 +103,19 @@ public static Builder builder() {
102103
@Nullable
103104
public abstract RouteOptions routeOptions();
104105

106+
/**
107+
* String of the language to be used for voice instructions. Defaults to en, and
108+
* can be any accepted instruction language. Will be <tt>null</tt> when the language provided
109+
* via {@link com.mapbox.api.matching.v5.MapboxMapMatching#language()} is not compatible
110+
* with API Voice.
111+
*
112+
* @return String compatible with voice instructions, null otherwise
113+
* @since 3.4.0
114+
*/
115+
@Nullable
116+
@SerializedName("voiceLocale")
117+
public abstract String voiceLanguage();
118+
105119
/**
106120
* Convert the current {@link MapMatchingMatching} to its builder holding the currently assigned
107121
* values. This allows you to modify a single variable and then rebuild the object resulting in
@@ -128,6 +142,7 @@ public DirectionsRoute toDirectionRoute() {
128142
.duration(duration())
129143
.distance(distance())
130144
.routeOptions(routeOptions())
145+
.voiceLanguage(voiceLanguage())
131146
.build();
132147
}
133148

@@ -223,7 +238,19 @@ public abstract static class Builder {
223238
* @return this builder for chaining options together
224239
* @since 3.0.0
225240
*/
226-
public abstract MapMatchingMatching.Builder routeOptions(@Nullable RouteOptions routeOptions);
241+
public abstract Builder routeOptions(@Nullable RouteOptions routeOptions);
242+
243+
/**
244+
* String of the language to be used for voice instructions. Defaults to en, and
245+
* can be any accepted instruction language. Should be <tt>null</tt> when the language provided
246+
* via {@link com.mapbox.api.matching.v5.MapboxMapMatching#language()} is not
247+
* compatible with API Voice.
248+
*
249+
* @param voiceLanguage String compatible with voice instructions, null otherwise
250+
* @return this builder for chaining options together
251+
* @since 3.4.0
252+
*/
253+
public abstract Builder voiceLanguage(@Nullable String voiceLanguage);
227254

228255
/**
229256
* Build a new {@link MapMatchingMatching} object.

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
import android.support.annotation.NonNull;
44
import android.support.annotation.Nullable;
5+
56
import com.google.auto.value.AutoValue;
67
import com.google.gson.Gson;
8+
import com.google.gson.GsonBuilder;
79
import com.google.gson.TypeAdapter;
10+
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
811

912
import java.io.Serializable;
1013
import java.util.List;
@@ -99,6 +102,21 @@ public static TypeAdapter<MapMatchingResponse> typeAdapter(Gson gson) {
99102
return new AutoValue_MapMatchingResponse.GsonTypeAdapter(gson);
100103
}
101104

105+
/**
106+
* Create a new instance of this class by passing in a formatted valid JSON String.
107+
*
108+
* @param json a formatted valid JSON string defining a GeoJson Map Matching response
109+
* @return a new instance of this class defined by the values passed inside this static factory
110+
* method
111+
* @since 3.4.0
112+
*/
113+
public static MapMatchingResponse fromJson(String json) {
114+
GsonBuilder gson = new GsonBuilder();
115+
gson.registerTypeAdapterFactory(MapMatchingAdapterFactory.create());
116+
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
117+
return gson.create().fromJson(json, MapMatchingResponse.class);
118+
}
119+
102120
/**
103121
* This builder can be used to set the values describing the {@link MapMatchingResponse}.
104122
*
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.mapbox.api.matching.v5.models;
2+
3+
import com.mapbox.core.TestUtils;
4+
5+
import org.junit.Test;
6+
7+
import static org.junit.Assert.assertEquals;
8+
import static org.junit.Assert.assertNull;
9+
10+
public class MapMatchingMatchingTest extends TestUtils {
11+
12+
private static final String MAP_MATCHING_V5_VOICE_LANGUAGE_JSON = "map_matching_v5_voice_language.json";
13+
private static final String MAP_MATCHING_V5_INVALID_VOICE_LANGUAGE_JSON = "map_matching_v5_invalid_voice_language.json";
14+
private static final int FIRST_ROUTE = 0;
15+
16+
@Test
17+
public void directionsRoute_doesReturnVoiceLocale() throws Exception {
18+
String json = loadJsonFixture(MAP_MATCHING_V5_VOICE_LANGUAGE_JSON);
19+
MapMatchingResponse response = MapMatchingResponse.fromJson(json);
20+
MapMatchingMatching matching = response.matchings().get(FIRST_ROUTE);
21+
22+
String voiceLanguage = matching.voiceLanguage();
23+
24+
assertEquals("en-US", voiceLanguage);
25+
}
26+
27+
@Test
28+
public void directionsRouteWithInvalidLanguage_doesReturnNullVoiceLanguage() throws Exception {
29+
String json = loadJsonFixture(MAP_MATCHING_V5_INVALID_VOICE_LANGUAGE_JSON);
30+
MapMatchingResponse response = MapMatchingResponse.fromJson(json);
31+
MapMatchingMatching matching = response.matchings().get(FIRST_ROUTE);
32+
33+
String voiceLanguage = matching.voiceLanguage();
34+
35+
assertNull(voiceLanguage);
36+
}
37+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"matchings":[{"confidence":0.8903306361380453,"geometry":"ahkccB_~_rXIf@}@vFwWcPmAs@}JaGoMsIwMyI{]sUiDuBsg@i[","legs":[{"summary":"Adalbertstraße","weight":113.7,"duration":101.1,"steps":[{"intersections":[{"classes":["restricted"],"out":0,"entry":[true],"bearings":[292],"location":[13.418992,52.500625]}],"driving_side":"right","geometry":"ahkccB_~_rXIf@}@vF","mode":"driving","maneuver":{"bearing_after":292,"bearing_before":0,"location":[13.418992,52.500625],"modifier":"left","type":"depart","instruction":"התכוונן צפון מערב"},"weight":19.3,"duration":6.7,"name":"","distance":10.5,"voiceInstructions":[{"distanceAlongGeometry":10.5,"announcement":"התכוונן צפון מערב, ואז פנה ימינה לAdalbertstraße","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">התכוונן צפון מערב, ואז פנה ימינה לAdalbertstraße</prosody></amazon:effect></speak>"}]},{"intersections":[{"out":0,"in":1,"entry":[true,false,true],"bearings":[30,120,210],"location":[13.418848,52.500661]}],"driving_side":"right","geometry":"ijkccB_u_rXwWcPmAs@","mode":"driving","maneuver":{"bearing_after":22,"bearing_before":292,"location":[13.418848,52.500661],"modifier":"right","type":"turn","instruction":"פנה ימינה לAdalbertstraße"},"weight":94.4,"duration":94.4,"name":"Adalbertstraße","distance":52.5,"voiceInstructions":[{"distanceAlongGeometry":5.6,"announcement":"הגעת אל היעד הראשונה שלך משמאלך","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">הגעת אל היעד הראשונה שלך משמאלך</prosody></amazon:effect></speak>"}]},{"intersections":[{"in":0,"entry":[true],"bearings":[202],"location":[13.419148,52.501096]}],"driving_side":"right","geometry":"oelccBwg`rX","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":22,"location":[13.419148,52.501096],"modifier":"left","type":"arrive","instruction":"הגעת אל היעד הראשונה שלך משמאלך"},"weight":0,"duration":0,"name":"Adalbertstraße","distance":0,"voiceInstructions":[]}],"distance":63},{"summary":"Adalbertstraße","weight":158,"duration":146,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[22],"location":[13.419148,52.501096]},{"out":0,"in":2,"entry":[true,true,false,true],"bearings":[30,120,195,300],"location":[13.419277,52.501287]}],"driving_side":"right","geometry":"oelccBwg`rX}JaGoMsIwMyI","mode":"driving","maneuver":{"bearing_after":22,"bearing_before":0,"location":[13.419148,52.501096],"modifier":"left","type":"depart","instruction":"התכוונן צפון מזרח על Adalbertstraße"},"weight":158,"duration":146,"name":"Adalbertstraße","distance":80,"voiceInstructions":[{"distanceAlongGeometry":80,"announcement":"התכוונן צפון מזרח על Adalbertstraße לאורך 300 רגל","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">התכוונן צפון מזרח על Adalbertstraße לאורך 300 רגל</prosody></amazon:effect></speak>"},{"distanceAlongGeometry":38.4,"announcement":"בעוד 200 רגל, אתה תגיע אל היעד השניה שלך","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">בעוד 200 רגל, אתה תגיע אל היעד השניה שלך</prosody></amazon:effect></speak>"},{"distanceAlongGeometry":5.5,"announcement":"הגעת אל היעד השניה שלך מימינך","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">הגעת אל היעד השניה שלך מימינך</prosody></amazon:effect></speak>"}]},{"intersections":[{"in":0,"entry":[true],"bearings":[204],"location":[13.41962,52.501755]}],"driving_side":"right","geometry":"unmccBgearX","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":24,"location":[13.41962,52.501755],"modifier":"right","type":"arrive","instruction":"הגעת אל היעד השניה שלך מימינך"},"weight":0,"duration":0,"name":"Adalbertstraße","distance":0,"voiceInstructions":[]}],"distance":80},{"summary":"Adalbertstraße","weight":109.4,"duration":109.3,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[24],"location":[13.41962,52.501755]},{"out":0,"in":2,"entry":[true,true,false,true],"bearings":[30,120,210,300],"location":[13.419982,52.502249]}],"driving_side":"right","geometry":"unmccBgearX{]sUiDuB","mode":"driving","maneuver":{"bearing_after":24,"bearing_before":0,"location":[13.41962,52.501755],"modifier":"right","type":"depart","instruction":"התכוונן צפון מזרח על Adalbertstraße"},"weight":109.4,"duration":109.3,"name":"Adalbertstraße","distance":70.4,"voiceInstructions":[{"distanceAlongGeometry":70.4,"announcement":"התכוונן צפון מזרח על Adalbertstraße לאורך 300 רגל","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">התכוונן צפון מזרח על Adalbertstraße לאורך 300 רגל</prosody></amazon:effect></speak>"},{"distanceAlongGeometry":45.1,"announcement":"בעוד 200 רגל, אתה תגיע אל היעד השלישית שלך","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">בעוד 200 רגל, אתה תגיע אל היעד השלישית שלך</prosody></amazon:effect></speak>"},{"distanceAlongGeometry":6.4,"announcement":"הגעת אל היעד השלישית שלך משמאלך","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">הגעת אל היעד השלישית שלך משמאלך</prosody></amazon:effect></speak>"}]},{"intersections":[{"in":0,"entry":[true],"bearings":[203],"location":[13.420041,52.502334]}],"driving_side":"right","geometry":"{rnccBq_brX","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":23,"location":[13.420041,52.502334],"modifier":"left","type":"arrive","instruction":"הגעת אל היעד השלישית שלך משמאלך"},"weight":0,"duration":0,"name":"Adalbertstraße","distance":0,"voiceInstructions":[]}],"distance":70.4},{"summary":"Adalbertstraße","weight":7.1,"duration":7.1,"steps":[{"intersections":[{"out":0,"entry":[true],"bearings":[23],"location":[13.420041,52.502334]}],"driving_side":"right","geometry":"{rnccBq_brXsg@i[","mode":"driving","maneuver":{"bearing_after":23,"bearing_before":0,"location":[13.420041,52.502334],"modifier":"left","type":"depart","instruction":"התכוונן צפון מזרח על Adalbertstraße"},"weight":7.1,"duration":7.1,"name":"Adalbertstraße","distance":78.5,"voiceInstructions":[{"distanceAlongGeometry":78.5,"announcement":"התכוונן צפון מזרח על Adalbertstraße, ואז הגעת אל היעד ה שלך מימינך","ssmlAnnouncement":"<speak><amazon:effect name=\"drc\"><prosody rate=\"1.08\">התכוונן צפון מזרח על Adalbertstraße, ואז הגעת אל היעד ה שלך מימינך</prosody></amazon:effect></speak>"}]},{"intersections":[{"in":0,"entry":[true],"bearings":[203],"location":[13.420494,52.502984]}],"driving_side":"right","geometry":"o{occB{{brX","mode":"driving","maneuver":{"bearing_after":0,"bearing_before":23,"location":[13.420494,52.502984],"modifier":"right","type":"arrive","instruction":"הגעת אל היעד ה שלך מימינך"},"weight":0,"duration":0,"name":"Adalbertstraße","distance":0,"voiceInstructions":[]}],"distance":78.5}],"weight_name":"routability","weight":388.20000000000005,"duration":363.5,"distance":291.9,"voiceLocale":null}],"tracepoints":[{"alternatives_count":0,"waypoint_index":0,"matchings_index":0,"name":"","location":[13.418992,52.500625]},{"alternatives_count":0,"waypoint_index":1,"matchings_index":0,"name":"Adalbertstraße","location":[13.419148,52.501096]},{"alternatives_count":0,"waypoint_index":2,"matchings_index":0,"name":"Adalbertstraße","location":[13.41962,52.501755]},{"alternatives_count":1,"waypoint_index":3,"matchings_index":0,"name":"Adalbertstraße","location":[13.420041,52.502334]},{"alternatives_count":1,"waypoint_index":4,"matchings_index":0,"name":"Adalbertstraße","location":[13.420494,52.502984]}],"code":"Ok"}

0 commit comments

Comments
 (0)