Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix setting a 0 0 coordinate on Android #681

Merged
merged 1 commit into from
Nov 4, 2024
Merged
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
21 changes: 11 additions & 10 deletions packages/vscode-extension/src/devices/AndroidEmulatorDevice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,17 @@ export class AndroidEmulatorDevice extends DeviceBase {
"location_mode",
"3",
]);
// note that geo fix command takes arguments: $longitude , $latitude so the order is reversed compared to most conventions
await exec(ADB_PATH, [
"-s",
this.serial!,
"emu",
"geo",
"fix",
settings.location.longitude.toString(),
settings.location.latitude.toString(),
]);

// This is a work around for the problem with emu geo command not working when passed, 0 0 coordinates
// when provided coordinates are close enough to 0 that the adb assumes they are 0 we pass the smallest
// working number instead. Moreover note that geo fix command takes arguments:
// $longitude , $latitude so the order is reversed compared to most conventions
const areCoordinatesToCloseToZero =
km1chno marked this conversation as resolved.
Show resolved Hide resolved
Math.abs(settings.location.latitude) < 0.00001 &&
Math.abs(settings.location.longitude) < 0.00001;
const lat = areCoordinatesToCloseToZero ? "0.00001" : settings.location.latitude.toString();
const long = areCoordinatesToCloseToZero ? "0.00001" : settings.location.longitude.toString();
await exec(ADB_PATH, ["-s", this.serial!, "emu", "geo", "fix", long, lat]);
}
return shouldRestart;
}
Expand Down