Simulate location in iOS Simulator tests: GPS fixes, routes, geofences
Simulate location on the iOS Simulator and Android Emulator: simctl, XCUILocation, adb emu geo fix, routes, geofence timing, and GPS versus IP geolocation.
- Written by
- Yuvan Sundrani
- Read time
- 7 min read
- Published
.png)
Key Takeaways
- Xcode's test-plan simulated location applies only to code in the test bundle; a UI test has to set XCUIDevice.shared.location for the app to see it.
- geo fix takes longitude first. simctl and most app code take latitude first, so a swapped pair lands in the wrong hemisphere without an error.
- Android's geofence service uses network location on most devices, so a mocked GPS fix alone may not fire a geofence, and alerts can arrive minutes late.
- iOS region monitoring allows 20 conditions per app and needs network connectivity to report changes on time.
- GPS position and IP geolocation are separate inputs; an app that checks both needs both set.
On the iOS Simulator, set location with xcrun simctl location or, inside a UI test, XCUIDevice.shared.location; on the Android Emulator, use adb emu geo fix with longitude first. Geofences then need the platform's timing rules, and region checks may need the IP address too.
GPS vs IP geolocation in app testing
| Input | Where the app reads it | What sets it in a test |
|---|---|---|
| GPS fix | Core Location, LocationManager, fused provider | simctl location, XCUILocation, geo fix, route playback |
| Network location | Android geofencing and coarse location | The device's network provider; a mocked GPS fix may not reach it |
| IP geolocation | Your backend or a third-party API | The egress IP of the device's traffic |
A common test failure: setting one input and asserting on a feature that reads another. A delivery app that shows nearby stores from GPS but prices from the IP's country passes a GPS-only test while showing the wrong currency.
Simulate location on the iOS Simulator with simctl
simctl gained location control in Xcode 14; Apple's release notes describe it as supporting simulated location, scenarios, and interpolation between waypoints, and point to xcrun simctl location for details:
\xcrun simctl location booted set 37.7749,-122.4194\
xcrun simctl location booted start --speed=15 \\\
37.7749,-122.4194 37.7793,-122.4192 37.7841,-122.4075\
xcrun simctl location booted clear\\The CLI's own help lists the built-in scenarios and the interval and distance options. Apple doesn't publish them on the web, so check xcrun simctl location --help on the Xcode version CI uses.
Inside XCTest, Apple's guide to simulating location in tests has a caveat UI tests run into: a simulated location set in the test plan changes location only for code running in the test bundle. A UI test drives the app as a separate process, so the app never sees it.
The guide's fix is to set the device location from the test:
XCUIDevice.shared.location = XCUILocation(
location: CLLocation(latitude: 37.334886, longitude: -122.008988))
The same guide covers GPX files for journeys: the test plan's Simulated Location can point at a GPX file, and Xcode replays location, elevation and velocity from it while unit and integration tests run.
Android emulator GPS location with adb emu geo fix
The emulator console's geo fix sends a GPS fix through a mock location provider. The argument order is longitude latitude [altitude] [satellites] [velocity], with velocity in knots:
adb emu geo fix -122.4194 37.7749 # longitude, then latitude
adb -s emulator-5556 emu geo fix -122.4194 37.7749 # one emulator of several
adb emu geo nmea '$GPGGA,...' # raw NMEA, GGA or RMC sentences
San Francisco entered latitude first becomes geo fix 37.7749 -122.4194, a point in Antarctica, and nothing errors. Wrap the command in a helper that takes named arguments.
For movement, the emulator's Extended controls > Location > Routes plays a saved route or an imported GPX or KML file, with a playback speed multiplier and repeat. On a physical phone, Developer options > Select mock location app routes a mock provider app's positions to the system.

Why doesn't my geofence fire on the emulator?
Android's geofencing guide sets four constraints a test has to respect:
- Permissions. ACCESS_FINE_LOCATION, plus ACCESS_BACKGROUND_LOCATION when targeting API 29 or higher.
- Provider. On most devices the geofence service uses only network location for triggering, so a GPS-only mock may never fire it.
- Latency. Alerts are usually under 2 minutes late, 2 to 3 minutes under background location limits, and up to 6 minutes after the device has been stationary.
- Size. A minimum radius of 100 to 150 meters works best; GEOFENCE_TRANSITION_DWELL with a loitering delay avoids alerts from someone passing through.
A test that sets a point inside the fence and asserts the alert within five seconds fails for reasons unrelated to the app. Move the position in steps across the boundary, give the assertion a window measured in minutes, or test the geofence handler directly with a constructed event.
On iOS, Apple's region monitoring docs allow 20 monitored conditions per app, note that timely reporting needs network connectivity, and describe entry and exit events arriving within 3 to 5 minutes on average for regions between 1 and 400 meters. CLMonitor with CLCircularGeographicCondition is the current API; startMonitoring(for:) is deprecated.
The denied-permission path matters as much as the fence. Permission prompts in automated tests covers driving the location prompt to Deny and asserting the fallback.

Autosana for location testing
Autosana is an AI end-to-end testing agent for iOS, Android and web apps. We set the GPS position and the IP country as separate inputs, which matches how apps actually read location.
Autosana key features for location
- GPS position between steps. In an Autosana sandbox, autosana sandbox set location 37.77,-122.41 moves the device, latitude first, and the next step's screenshot shows whether the map or the store list reacted.
- IP country for a whole run. Our proxy location sends all device traffic from a residential IP in the chosen country, for example --location MX, on web and Android emulator runs. It also moves the GPS position to that country unless the run's language names one, sets the time zone from the exit IP, and fails with Location proxy unavailable rather than falling back to a US IP.
autosana sandbox set location 37.7749,-122.4194 --description "Outside the delivery zone"
autosana sandbox look --description "Out-of-zone banner"
autosana sandbox set location 37.7793,-122.4192 --description "Inside the zone"
autosana sandbox wait 2s
autosana sandbox look --description "Store list for the new zone"

A location run in our dashboard: summary, flagged issue, each step with timing, and the device screen after the move. Source: Autosana docs video.
Autosana customer results
- Gobi (social maps app) replaced 13 brittle Maestro tests with 30+ Autosana tests, and nightly runs caught six real bugs in five days. Their CTO: "It's like a human is using your app." See the Gobi case study.
Why use Autosana for location testing?
- GPS and IP set separately. Each feature gets tested against the input it actually reads.
- Routes as steps with screenshots. Each move leaves an image of what the app showed.
- Region rules without a VPN. The proxy location changes what the backend sees for the whole run.
- No field testing for the regression suite. Point locations and short routes run on every PR.
- Free to try. Pay as you go starts with up to 1,000 free AI actions a month.
The localization testing guide covers the language side of region changes.
The AVD configuration these commands assume is in Android Emulator setup.
Other emulator commands are in the adb commands cheat sheet.
Conclusion
Point locations and short routes belong in simulator and emulator runs on every PR: they're repeatable and cover map rendering, distance logic, search radius and the denied-permission path.
Geofence delivery belongs in a slower suite with minute-scale assertions, or in unit tests that feed the handler a constructed event. Region rules that depend on the IP address need the proxy set, because no GPS command changes what the backend sees.
FAQs
1. How do I set the iOS Simulator location from the command line?
xcrun simctl location booted set <latitude>,<longitude>, available since Xcode 14.
2. Why does my UI test ignore the simulated location?
The test plan's location applies to the test bundle only. Set XCUIDevice.shared.location.
3. What order does adb emu geo fix take?
Longitude first, then latitude, then optional altitude, satellites and velocity in knots.
4. Why doesn't my geofence fire on the emulator?
Most devices trigger geofences from network location, and alerts can arrive minutes late.
5. How many regions can an iOS app monitor?
Twenty conditions per app at a time.
6. Can Autosana change the GPS location during a run?
Yes. autosana sandbox set location moves it between steps, latitude first.
Sources


