Skip to content

Commit 0c5bc86

Browse files
VysotskiVadimgithub-actions[bot]
authored andcommitted
Voice unit parameter for Map Matching API (#10510) (#10540)
GitOrigin-RevId: d72beb2c35cf40dbdb2e4f7f57251d92d50d5c97
1 parent 3de722e commit 0c5bc86

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Added `MapMatchingOptions.voiceUnits` which allows applications to specify the unit system used for voice instructions in Map Matching.

navigation/src/main/java/com/mapbox/navigation/core/mapmatching/MapMatchingExtras.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,21 @@ object MapMatchingExtras {
6262
* Based on TomTom OpenLR location references.
6363
*/
6464
const val OPENLR_FORMAT_TOMTOM = "tomtom"
65+
66+
/**
67+
* Voice units: imperial (default)
68+
*/
69+
const val VOICE_UNITS_IMPERIAL = "imperial"
70+
71+
/**
72+
* Voice units: british imperial
73+
*/
74+
const val VOICE_UNITS_BRITISH_IMPERIAL = "british_imperial"
75+
76+
/**
77+
* Voice units: metric
78+
*/
79+
const val VOICE_UNITS_METRIC = "metric"
6580
}
6681

6782
/**
@@ -110,3 +125,15 @@ annotation class MapMatchingOpenLRSpec
110125
MapMatchingExtras.OPENLR_FORMAT_TOMTOM,
111126
)
112127
annotation class MapMatchingOpenLRFormat
128+
129+
/**
130+
* Supported voice units.
131+
* @see [MapMatchingOptions.Builder.voiceUnits]
132+
*/
133+
@Retention(AnnotationRetention.BINARY)
134+
@StringDef(
135+
MapMatchingExtras.VOICE_UNITS_IMPERIAL,
136+
MapMatchingExtras.VOICE_UNITS_BRITISH_IMPERIAL,
137+
MapMatchingExtras.VOICE_UNITS_METRIC,
138+
)
139+
annotation class MapMatchingVoiceUnits

navigation/src/main/java/com/mapbox/navigation/core/mapmatching/MapMatchingOptions.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import java.net.URLEncoder
3232
* @param ignore defines defines certain routing restrictions to ignore when map matching.
3333
* @param openlrSpec defines the logical format for OpenLR encoded [coordinates].
3434
* @param openlrFormat defines binary format for OpenLR encoded coordinates.
35+
* @param voiceUnits defines units for voice instructions.
3536
*/
3637
@ExperimentalPreviewMapboxNavigationAPI
3738
class MapMatchingOptions private constructor(
@@ -54,6 +55,8 @@ class MapMatchingOptions private constructor(
5455
val ignore: List<String>?,
5556
val openlrSpec: String?,
5657
val openlrFormat: String?,
58+
@MapMatchingVoiceUnits
59+
val voiceUnits: String?,
5760
) {
5861
/**
5962
* Compares if options are the same
@@ -81,6 +84,7 @@ class MapMatchingOptions private constructor(
8184
if (ignore != other.ignore) return false
8285
if (openlrSpec != other.openlrSpec) return false
8386
if (openlrFormat != other.openlrFormat) return false
87+
if (voiceUnits != other.voiceUnits) return false
8488

8589
return true
8690
}
@@ -106,6 +110,7 @@ class MapMatchingOptions private constructor(
106110
result = 31 * result + (ignore?.hashCode() ?: 0)
107111
result = 31 * result + (openlrSpec?.hashCode() ?: 0)
108112
result = 31 * result + (openlrFormat?.hashCode() ?: 0)
113+
result = 31 * result + (voiceUnits?.hashCode() ?: 0)
109114
return result
110115
}
111116

@@ -130,7 +135,8 @@ class MapMatchingOptions private constructor(
130135
"waypointNames=$waypointNames, " +
131136
"ignore=$ignore, " +
132137
"openlrSpec=$openlrSpec, " +
133-
"openlrFormat=$openlrFormat" +
138+
"openlrFormat=$openlrFormat, " +
139+
"voiceUnits=$voiceUnits" +
134140
")"
135141
}
136142

@@ -155,6 +161,7 @@ class MapMatchingOptions private constructor(
155161
private var ignore: List<String>? = null
156162
private var openlrSpec: String? = null
157163
private var openlrFormat: String? = null
164+
private var voiceUnits: String? = null
158165

159166
/**
160167
* Required parameter.
@@ -352,6 +359,17 @@ class MapMatchingOptions private constructor(
352359
return this
353360
}
354361

362+
/**
363+
* Optional parameter.
364+
* @param voiceUnits defines units for voice instructions.
365+
* Must be used with [voiceInstructions] set to true.
366+
* @return this [Builder]
367+
*/
368+
fun voiceUnits(@MapMatchingVoiceUnits voiceUnits: String?): Builder {
369+
this.voiceUnits = voiceUnits
370+
return this
371+
}
372+
355373
/**
356374
* Builds [MapMatchingOptions] based on provided values.
357375
*/
@@ -378,6 +396,7 @@ class MapMatchingOptions private constructor(
378396
ignore = ignore,
379397
openlrSpec = openlrSpec,
380398
openlrFormat = openlrFormat,
399+
voiceUnits = voiceUnits,
381400
)
382401
}
383402

@@ -408,6 +427,7 @@ class MapMatchingOptions private constructor(
408427
openlrSpec.toParam("openlr_spec"),
409428
openlrFormat.toParam("openlr_format"),
410429
tidy.toParam("tidy"),
430+
voiceUnits.toParam("voice_units"),
411431
)
412432
.joinToString(
413433
prefix = prefix,

navigation/src/test/java/com/mapbox/navigation/core/mapmatching/MapMatchingOptionsTest.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ class MapMatchingOptionsTest {
115115
assertNull(
116116
httpUrl.queryParameter("openlr_format"),
117117
)
118+
assertNull(
119+
httpUrl.queryParameter("voice_units"),
120+
)
118121
}
119122

120123
@Test
@@ -383,6 +386,22 @@ class MapMatchingOptionsTest {
383386
)
384387
}
385388

389+
@Test
390+
fun `voice units metric`() {
391+
val options = createOptionsBuilderWithRequiredParams()
392+
.voiceInstructions(true)
393+
.voiceUnits(MapMatchingExtras.VOICE_UNITS_METRIC)
394+
.build()
395+
396+
val url = options.toURL("***")
397+
398+
val httpUrl = url.toHttpUrl()
399+
assertEquals(
400+
"metric",
401+
httpUrl.queryParameter("voice_units"),
402+
)
403+
}
404+
386405
@Test
387406
fun `waypoints names`() {
388407
val options = createOptionsBuilderWithRequiredParams()

0 commit comments

Comments
 (0)