How to emulate GPS location in the Android Emulator
Codemia Knowledge Hub ·
The Android Emulator gives you three ways to set a fake GPS location: the Extended Controls UI in Android Studio, the geo fix command over a console connection, and adb emu geo fix from a terminal. The UI suits quick manual testing; the commands suit scripts and CI pipelines. Note that geo fix takes longitude first, then latitude.
Method 1: Extended Controls UI
The fastest option for manual testing, with a map for picking locations.
- 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, or click a point on the map.
- Click Send to push the location to the emulator.
This panel also loads GPX and KML route files. Drag a GPX file onto the map or use Load GPX/KML, then play the route back at configurable speed. It is the easiest way to test driving navigation, fitness tracking or geofencing.
Mock location in instrumented tests
For instrumented tests, use the FusedLocationProviderClient test API instead of the emulator controls:
This works on both emulators and physical devices (with developer options enabled). The Extended Controls UI and geo fix only work with emulators, so on a physical device use setMockLocation().
Method 2: adb emu geo fix and the console
For scripted testing, send geo fix to the emulator console. This fits CI pipelines and shell scripts that change location programmatically.
The parameter order, longitude first, is the opposite of most mapping APIs and a frequent source of mistakes.
To use the raw telnet interface, you need the console auth token, which the console has required since Android Studio 2.0:
Simulating movement
Each geo fix sets a single point. For movement, send a sequence with a delay between points:
Method 3: ADB shell commands
ADB shell commands help when you need to broadcast location changes to apps listening for location intents:
On CI, adb emu is preferred because it does not need a separate telnet connection.
Comparing the 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) |
Playing a route from a GPX file
GPX files define waypoints with timestamps, which the emulator plays back in order:
Load the file in the Extended Controls Location tab. The emulator interpolates between waypoints based on the timestamps, producing realistic movement.
Testing edge-case locations
Test location-based apps against boundary conditions:
And rapid location changes:
The app should detect the impossible speed and either filter the jump or treat it as a new session.
Permissions and Google APIs
Use an AVD whose system image includes Google Play Services (or Google APIs). FusedLocationProviderClient requires Play Services, which plain AOSP images do not include.
The app must also declare and be granted location permissions. Without them, the emulator accepts the location but the app receives no updates.
Related reading
- How to enable back/left swipe gesture in UINavigationController after setting leftBarButtonItem?
- How to Enable Internal App Sharing for Android?
- How to enable zoom controls and pinch zoom in a WebView?
- How to encode a URL in Swift
- How to exchange elements in swift array?
- How to exclude properties from Swift Codable?
- How to export fat Cocoa Touch Framework for Simulator and Device?
- How to fade a UIVisualEffectView and/or UIBlurEffect in and out?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseNo course covers this one yet
Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.
Build my courseData Structures & Algorithms practice on Codemia
Step through 300+ coding interview problems with animated visualisers that show the data structure changing as the code runs. The Blind 75 are free.