Android Emulator
GPS Emulation
Location Spoofing
Android Development
Developer Tools

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.

  1. Launch your AVD from the AVD Manager in Android Studio.
  2. Click the three-dot menu (...) in the emulator toolbar to open Extended Controls.
  3. Select the Location tab.
  4. Enter latitude and longitude, or click a point on the map.
  5. 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:

kotlin
1import android.location.Location
2import android.os.SystemClock
3import com.google.android.gms.location.FusedLocationProviderClient
4import com.google.android.gms.location.LocationServices
5
6val fusedClient: FusedLocationProviderClient =
7    LocationServices.getFusedLocationProviderClient(context)
8
9val mockLocation = Location("mock").apply {
10    latitude = 37.4220
11    longitude = -122.0841
12    accuracy = 10f
13    time = System.currentTimeMillis()
14    elapsedRealtimeNanos = SystemClock.elapsedRealtimeNanos()
15}
16
17fusedClient.setMockMode(true)
18fusedClient.setMockLocation(mockLocation)

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.

bash
# Connect to the emulator console
# The default port for the first emulator is 5554
adb emu geo fix -122.0841 37.4220

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:

bash
1# First, get the auth token
2cat ~/.emulator_console_auth_token
3
4# Connect and authenticate
5telnet localhost 5554
6auth <paste-token-here>
7geo fix -122.0841 37.4220

Simulating movement

Each geo fix sets a single point. For movement, send a sequence with a delay between points:

bash
1#!/bin/bash
2# Simulate walking along a street
3locations=(
4    "-122.0841 37.4220"
5    "-122.0845 37.4222"
6    "-122.0850 37.4225"
7    "-122.0855 37.4228"
8    "-122.0860 37.4230"
9)
10
11for loc in "${locations[@]}"; do
12    adb emu geo fix $loc
13    sleep 2
14done

Method 3: ADB shell commands

ADB shell commands help when you need to broadcast location changes to apps listening for location intents:

bash
1# Set mock location via the emulator console through ADB
2adb emu geo fix -122.0841 37.4220
3
4# Alternatively, allow an app to act as the mock location provider (Android 6.0+)
5adb shell appops set com.example.myapp android:mock_location allow

On CI, adb emu is preferred because it does not need a separate telnet connection.

Comparing the methods

MethodBest ForAutomationRoute SimulationSetup Effort
Extended Controls UIManual testing, visual route designNoneGPX/KML file importMinimal
adb emu geo fixShell scripts, CI pipelinesFullScript a sequence of pointsLow
Telnet geo fixLegacy scripts, debuggingFullScript a sequence of pointsModerate (auth token)
setMockLocation() APIInstrumented testsFull (in-test)Programmatic sequencesModerate (test setup)

Playing a route from a GPX file

GPX files define waypoints with timestamps, which the emulator plays back in order:

xml
1<?xml version="1.0" encoding="UTF-8"?>
2<gpx version="1.1" creator="manual">
3  <trk>
4    <name>Test Route</name>
5    <trkseg>
6      <trkpt lat="37.4220" lon="-122.0841">
7        <time>2025-01-01T00:00:00Z</time>
8      </trkpt>
9      <trkpt lat="37.4225" lon="-122.0845">
10        <time>2025-01-01T00:00:10Z</time>
11      </trkpt>
12      <trkpt lat="37.4230" lon="-122.0850">
13        <time>2025-01-01T00:00:20Z</time>
14      </trkpt>
15    </trkseg>
16  </trk>
17</gpx>

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:

bash
1# Equator / Prime Meridian intersection
2adb emu geo fix 0.0 0.0
3
4# International Date Line
5adb emu geo fix 180.0 0.0
6adb emu geo fix -180.0 0.0
7
8# North Pole
9adb emu geo fix 0.0 90.0
10
11# South Pole
12adb emu geo fix 0.0 -90.0
13
14# High altitude (include altitude as third parameter, in meters)
15adb emu geo fix -105.9378 39.7392 4300

And rapid location changes:

bash
1# Simulate teleportation (location jump)
2adb emu geo fix -122.4194 37.7749  # San Francisco
3sleep 1
4adb emu geo fix 2.3522 48.8566     # Paris

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.

xml
<!-- AndroidManifest.xml -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
kotlin
1// Request permissions at runtime (Android 6.0+)
2if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
3    != PackageManager.PERMISSION_GRANTED) {
4    ActivityCompat.requestPermissions(
5        this,
6        arrayOf(Manifest.permission.ACCESS_FINE_LOCATION),
7        LOCATION_PERMISSION_REQUEST
8    )
9}

Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No 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 course
Data 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.

Practice algorithms