How to emulate GPS location in the Android Emulator?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
The Android Emulator provides three ways to set a fake GPS location: the Extended Controls UI in Android Studio, the geo fix command over a console connection, and the adb emu command from a terminal. Each approach serves a different workflow, from quick manual testing to scripted CI pipelines. This article covers all three methods with working examples, explains how to simulate routes, and addresses the common issues developers encounter.
Method 1: Extended Controls UI
This is the fastest approach for manual testing. It provides a map interface for picking locations visually.
- Launch your AVD from the AVD Manager in Android Studio.
- Click the three-dot menu (...) in the emulator toolbar to open Extended Controls.
- Select the Location tab.
- Enter latitude and longitude manually, or click a point on the map.
- Click Send to push the location to the emulator.
The emulator also supports loading GPX and KML route files from this panel. Drag a GPX file onto the map area or use the Load GPX/KML button to import a route, then play it back at configurable speed. This is the easiest way to test driving navigation, fitness tracking, or geofencing scenarios.
Setting a Location Programmatically in Tests
If you are running instrumented tests and need to mock location, use the FusedLocationProviderClient test API rather than the emulator controls:
This approach works in both emulator and physical device test runs (with developer options enabled).
Method 2: Console geo fix Command
For scripted testing, connect to the emulator's console over TCP and send geo fix commands. This is useful for CI pipelines or shell scripts that need to change location programmatically.
Note the parameter order: longitude comes first, then latitude. This is the opposite of what most mapping APIs use and is a frequent source of confusion.
If you need to use the raw telnet interface:
To simulate movement, send a sequence of geo fix commands with a delay between each:
Method 3: ADB Shell Commands
You can also set mock location through ADB shell commands, which is useful when you need to broadcast location changes to apps that listen for location intents:
For automated test suites that run on CI, the adb emu approach is preferred because it does not require establishing a separate telnet connection.
Comparison of Methods
| Method | Best For | Automation | Route Simulation | Setup Effort |
| Extended Controls UI | Manual testing, visual route design | None | GPX/KML file import | Minimal |
adb emu geo fix | Shell scripts, CI pipelines | Full | Script a sequence of points | Low |
Telnet geo fix | Legacy scripts, debugging | Full | Script a sequence of points | Moderate (auth token) |
setMockLocation() API | Instrumented tests | Full (in-test) | Programmatic sequences | Moderate (test setup) |
Setting Up GPX Route Files
GPX files let you define a series of waypoints with timestamps. The emulator plays them back in order, simulating real movement.
Load this file in the Extended Controls Location tab. The emulator interpolates between waypoints based on the timestamps, producing a realistic movement pattern.
Testing Edge Cases
Location-based apps should be tested against several boundary conditions:
Test that your app handles rapid location changes gracefully:
Your app should detect the impossible speed and either filter the jump or handle it as a new session.
Permissions and Runtime Checks
Before testing location features, ensure the emulator AVD has Google Play Services (or Google APIs) in its system image. Location testing also requires that the app has declared and been granted location permissions:
Common Pitfalls
- Reversing latitude and longitude in
geo fix. The command takes longitude first, unlike most APIs that expect latitude first. - Forgetting the emulator console auth token. Since Android Studio 2.0, the console requires authentication. Read the token from
~/.emulator_console_auth_token. - Testing on an AVD without Google APIs. The
FusedLocationProviderClientrequires Google Play Services, which is not included in plain AOSP system images. - Not granting location permissions before sending mock coordinates. The emulator will accept the location, but the app will not receive updates if it lacks permissions.
- Expecting
geo fixto produce continuous movement. Eachgeo fixcall sets a single point. For continuous movement, send a sequence of points or use a GPX file. - Using the emulator's built-in location on a physical device. The Extended Controls UI and
geo fixonly work with emulators. For physical devices, usesetMockLocation()with developer options enabled.
Summary
- Use the Extended Controls UI for quick manual testing with a visual map and GPX/KML route playback.
- Use
adb emu geo fix <longitude> <latitude>for scripted and CI-driven location testing. Remember that longitude comes first. - Use
setMockLocation()in instrumented tests for deterministic, in-process location mocking. - Test boundary conditions (poles, date line, altitude, teleportation) to catch edge cases in location handling.
- Always verify that the AVD has Google APIs and that the app has been granted location permissions.

