Skip to content

Commit 7473768

Browse files
committed
feat: add bearing and accuracy param into setGeoLocation
1 parent 48806da commit 7473768

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/commands/geolocation.js

+23
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ const GPS_COORDINATES_PATTERN = /data="(-?[\d.]+)\s+(-?[\d.]+)\s+(-?[\d.]+)"/;
2626
* @property {?number|string} [satellites=12] - Number of satellites being tracked (1-12).
2727
* This value is ignored on real devices.
2828
* @property {?number|string} [speed] - Valid speed value.
29+
* https://developer.android.com/reference/android/location/Location#setSpeed(float)
30+
* @property {?number|string} [bearing] - Valid bearing value.
31+
* https://developer.android.com/reference/android/location/Location#setBearing(float)
32+
* @property {?number|string} [accuracy] - Valid accuracy value.
33+
* https://developer.android.com/reference/android/location/Location#setAccuracy(float),
34+
* https://developer.android.com/reference/android/location/Criteria
2935
* Should be greater than 0.0 meters/second for real devices or 0.0 knots
3036
* for emulators.
3137
*/
@@ -61,6 +67,8 @@ export async function setGeoLocation (location, isEmulator = false) {
6167
const latitude = /** @type {string} */ (formatLocationValue('latitude'));
6268
const altitude = formatLocationValue('altitude', false);
6369
const speed = formatLocationValue('speed', false);
70+
const bearing = formatLocationValue('bearing', false);
71+
const accuracy = formatLocationValue('accuracy', false);
6472
if (isEmulator) {
6573
/** @type {string[]} */
6674
const args = [longitude, latitude];
@@ -97,8 +105,23 @@ export async function setGeoLocation (location, isEmulator = false) {
97105
args.push('-e', 'altitude', altitude);
98106
}
99107
if (!_.isNil(speed)) {
108+
if (_.toNumber(speed) < 0) {
109+
throw new Error(`${speed} is expected to be 0.0 or greater.`);
110+
}
100111
args.push('-e', 'speed', speed);
101112
}
113+
if (!_.isNil(bearing)) {
114+
if (!_.inRange(_.toNumber(bearing), 0, 360)) {
115+
throw new Error(`${accuracy} is expected to be [0, 360) range.`);
116+
}
117+
args.push('-e', 'bearing', bearing);
118+
}
119+
if (!_.isNil(accuracy)) {
120+
if (_.toNumber(accuracy) < 0) {
121+
throw new Error(`${accuracy} is expected to be 0.0 or greater.`);
122+
}
123+
args.push('-e', 'accuracy', accuracy);
124+
}
102125
args.push(LOCATION_SERVICE);
103126
await this.adb.shell(args);
104127
}

0 commit comments

Comments
 (0)