How to Fake Your GPS Location on Android to Trick Apps
Android offers a unique feature that allows you to set any app as your location provider, meaning the entire system will use the latitude and longitude that app supplies. In this article, I’ll show you how to use this feature and even how to write your own app for GPS spoofing.
Why Spoof Your Location?
The idea came to me while writing an article about home isolation monitoring apps. That’s when I discovered you can change the location provider in Android, opening up a lot of interesting possibilities for users.
From a user’s perspective, it’s simple: just install a special app, enable Developer Mode in your settings, and select the installed app as your mock location provider. There are tons of these apps—some basic, others more advanced, letting you not only set fixed coordinates but also change them on a schedule or play back pre-recorded routes to simulate movement. Just search for “Fake GPS” and pick one you like.
Note: This method isn’t foolproof. Apps can detect if a mock location provider is active, and serious apps may not be easily tricked.
How Does It Work?
I wanted to understand how this mechanism works and create my own spoofing app. I started by reverse-engineering a free app called FakeGPS 5.0.0. The app displays a map where you can set a marker and use “Start” and “Stop” buttons to broadcast the selected coordinates.
Using JEB Decompiler, I found that the app requests the android.permission.ACCESS_MOCK_LOCATION
permission in its manifest, along with others like:
- android.permission.INTERNET
- android.permission.ACCESS_NETWORK_STATE
- android.permission.WRITE_EXTERNAL_STORAGE
- android.permission.WAKE_LOCK
- android.permission.ACCESS_COARSE_LOCATION
- android.permission.ACCESS_FINE_LOCATION
- android.permission.ACCESS_MOCK_LOCATION
- android.permission.WRITE_SETTINGS
- com.android.vending.BILLING
The main activity is standard, but there’s a service called FakeGPSService that does the real work. Here’s a simplified version of what it does:
- Initializes
LocationManager
withgetSystemService("location")
. - Removes any existing test provider named “gps” with
removeTestProvider
. - Adds a new test provider with
addTestProvider
and enables it withsetTestProviderEnabled("gps", true)
. - When the user changes coordinates, it creates a new
Location
object, sets the desired latitude and longitude, and updates the test provider withsetTestProviderLocation
.
Writing Your Own Mock Location Provider
I decided to make a simple demo app to show how this works. The app will set hardcoded fake coordinates once when the provider is created. Here’s how you can do it:
- Create a new Android Studio project with an empty activity.
- Add
android.permission.ACCESS_MOCK_LOCATION
to your manifest. Android Studio may warn you that this permission is only available to system apps or in test manifests—just follow the prompts to resolve this. - Add two buttons to your main activity layout:
<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <Button android:id="@+id/btnDelGPS" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="DelGPS" android:text="Delete GPS Provider" /> <Button android:id="@+id/btnAddGPS" android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="AddGPS" android:text="Add GPS Provider" /> </LinearLayout>
And the corresponding Java code:
public class MainActivity extends Activity { LocationManager mLocationManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize LocationManager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); } public void AddGPS(View view) { // Add test provider mLocationManager.addTestProvider(LocationManager.GPS_PROVIDER, false, false, false, false, true, true, true, android.location.Criteria.POWER_LOW, android.location.Criteria.ACCURACY_FINE); // Enable test provider mLocationManager.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true); // Set fake location Location newLocation = new Location(LocationManager.GPS_PROVIDER); newLocation.setLatitude(55.75578); newLocation.setLongitude(37.61786); newLocation.setTime(System.currentTimeMillis()); newLocation.setAccuracy(25); newLocation.setElapsedRealtimeNanos(System.nanoTime()); mLocationManager.setTestProviderLocation(LocationManager.GPS_PROVIDER, newLocation); } public void DelGPS(View view) { // Remove test provider mLocationManager.removeTestProvider(LocationManager.GPS_PROVIDER); } }
Compile and install the app. Then, in your phone’s Developer Options, select your app as the mock location provider. Launch your app and tap “Add GPS Provider.”
If nothing happens, that’s normal. If you run the app again and get an error, it may be because the test provider already exists. Just tap “Delete GPS Provider” and then “Add GPS Provider” again.
Testing the Spoofed Location
Minimize your app and open Yandex Maps—you should appear at Red Square in Moscow, as intended. Success!
However, if you try Google Maps, you might end up somewhere else. This is because Google Maps may use its own location services. To fix this, disable Google Location Accuracy in your phone’s settings. This forces the phone to use your test provider’s coordinates.
After disabling Google Location, try again—now you should appear at Red Square in both Yandex and Google Maps.
Making It Work Everywhere
To fully spoof your location, including for apps that use Google’s Fused Location Provider, you need to use Google’s APIs. The FakeGPS app does this by using GoogleApiClient
and the following methods:
LocationServices.FusedLocationApi.setMockMode()
LocationServices.FusedLocationApi.setMockLocation()
Note: FusedLocationApi
is deprecated; use FusedLocationProviderClient
instead. Add this to your build.gradle
dependencies:
implementation 'com.google.android.gms:play-services-location:17.0.0'
Then, at the end of your AddGPS
function, add:
LocationServices.getFusedLocationProviderClient(this).setMockMode(true); LocationServices.getFusedLocationProviderClient(this).setMockLocation(newLocation);
Now your fake location will work in both Google Maps and Yandex Maps, even with Google Location enabled. Success!
Conclusion
This method lets you spoof your GPS coordinates on Android, but keep in mind that some apps can detect mock locations. For more advanced spoofing, you may need to dig deeper into Android’s location APIs.