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
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ mapmatching-fixtures:
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)" \
-o services-matching/src/test/resources/mapmatching_v5_waypoint_names.json

# MapMatching with valid voiceLanguage
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)" \
-o services-matching/src/test/resources/map_matching_v5_voice_language.json

# MapMatching with invalid voiceLanguage
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)" \
-o services-matching/src/test/resources/map_matching_v5_invalid_voice_language.json

optimization-fixtures:
# request an optimized car trip with no additional options
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)" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.SerializedName;
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;
import com.mapbox.api.directions.v5.MapboxDirections;
import com.mapbox.geojson.BoundingBox;
import com.mapbox.geojson.Geometry;
import com.mapbox.geojson.Point;
Expand Down Expand Up @@ -126,7 +127,8 @@ public static DirectionsRoute fromJson(String json) {

/**
* String of the language to be used for voice instructions. Defaults to en, and
* can be any accepted instruction language.
* can be any accepted instruction language. Will be <tt>null</tt> when the language provided
* via {@link MapboxDirections#language()} is not compatible with API Voice.
*
* @return String compatible with voice instructions, null otherwise
* @since 3.1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.mapbox.api.matching.v5.models;

import android.support.annotation.Nullable;

import com.google.auto.value.AutoValue;
import com.google.gson.Gson;
import com.google.gson.TypeAdapter;
import com.google.gson.annotations.SerializedName;
import com.mapbox.api.directions.v5.models.RouteLeg;
import com.mapbox.api.directions.v5.models.DirectionsRoute;
import com.mapbox.api.directions.v5.models.RouteLeg;
import com.mapbox.api.directions.v5.models.RouteOptions;

import java.io.Serializable;
Expand Down Expand Up @@ -102,6 +103,19 @@ public static Builder builder() {
@Nullable
public abstract RouteOptions routeOptions();

/**
* String of the language to be used for voice instructions. Defaults to en, and
* can be any accepted instruction language. Will be <tt>null</tt> when the language provided
* via {@link com.mapbox.api.matching.v5.MapboxMapMatching#language()} is not compatible
* with API Voice.
*
* @return String compatible with voice instructions, null otherwise
* @since 3.4.0
*/
@Nullable
@SerializedName("voiceLocale")
public abstract String voiceLanguage();

/**
* Convert the current {@link MapMatchingMatching} to its builder holding the currently assigned
* values. This allows you to modify a single variable and then rebuild the object resulting in
Expand All @@ -128,6 +142,7 @@ public DirectionsRoute toDirectionRoute() {
.duration(duration())
.distance(distance())
.routeOptions(routeOptions())
.voiceLanguage(voiceLanguage())
.build();
}

Expand Down Expand Up @@ -223,7 +238,19 @@ public abstract static class Builder {
* @return this builder for chaining options together
* @since 3.0.0
*/
public abstract MapMatchingMatching.Builder routeOptions(@Nullable RouteOptions routeOptions);
public abstract Builder routeOptions(@Nullable RouteOptions routeOptions);

/**
* String of the language to be used for voice instructions. Defaults to en, and
* can be any accepted instruction language. Should be <tt>null</tt> when the language provided
* via {@link com.mapbox.api.matching.v5.MapboxMapMatching#language()} is not
* compatible with API Voice.
*
* @param voiceLanguage String compatible with voice instructions, null otherwise
* @return this builder for chaining options together
* @since 3.4.0
*/
public abstract Builder voiceLanguage(@Nullable String voiceLanguage);

/**
* Build a new {@link MapMatchingMatching} object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.google.auto.value.AutoValue;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.TypeAdapter;
import com.mapbox.api.directions.v5.DirectionsAdapterFactory;

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

/**
* Create a new instance of this class by passing in a formatted valid JSON String.
*
* @param json a formatted valid JSON string defining a GeoJson Map Matching response
* @return a new instance of this class defined by the values passed inside this static factory
* method
* @since 3.4.0
*/
public static MapMatchingResponse fromJson(String json) {
GsonBuilder gson = new GsonBuilder();
gson.registerTypeAdapterFactory(MapMatchingAdapterFactory.create());
gson.registerTypeAdapterFactory(DirectionsAdapterFactory.create());
return gson.create().fromJson(json, MapMatchingResponse.class);
}

/**
* This builder can be used to set the values describing the {@link MapMatchingResponse}.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.mapbox.api.matching.v5.models;

import com.mapbox.core.TestUtils;

import org.junit.Test;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

public class MapMatchingMatchingTest extends TestUtils {

private static final String MAP_MATCHING_V5_VOICE_LANGUAGE_JSON = "map_matching_v5_voice_language.json";
private static final String MAP_MATCHING_V5_INVALID_VOICE_LANGUAGE_JSON = "map_matching_v5_invalid_voice_language.json";
private static final int FIRST_ROUTE = 0;

@Test
public void directionsRoute_doesReturnVoiceLocale() throws Exception {
String json = loadJsonFixture(MAP_MATCHING_V5_VOICE_LANGUAGE_JSON);
MapMatchingResponse response = MapMatchingResponse.fromJson(json);
MapMatchingMatching matching = response.matchings().get(FIRST_ROUTE);

String voiceLanguage = matching.voiceLanguage();

assertEquals("en-US", voiceLanguage);
}

@Test
public void directionsRouteWithInvalidLanguage_doesReturnNullVoiceLanguage() throws Exception {
String json = loadJsonFixture(MAP_MATCHING_V5_INVALID_VOICE_LANGUAGE_JSON);
MapMatchingResponse response = MapMatchingResponse.fromJson(json);
MapMatchingMatching matching = response.matchings().get(FIRST_ROUTE);

String voiceLanguage = matching.voiceLanguage();

assertNull(voiceLanguage);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +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"}
Loading