Set the location in iPhone Simulator

Viewed 137742

How can I set the location (as it's picked up in CoreLocation services) in the iPhone Simulator?

17 Answers

XCode 11.3 and prior:

Debug -> Location -> Custom Location

enter image description here

XCode 11.4+:

Features -> Location -> Custom Location

enter image description here

To find out which XCode version you have

$ /usr/bin/xcodebuild -version

In my delegate callback, I check to see if I'm running in a simulator (#if TARGET_ IPHONE_SIMULATOR) and if so, I supply my own, pre-looked-up, Lat/Long. To my knowledge, there's no other way.

You can easily share any desired location from the macOS Maps application to the Xcode simulator.

  1. From Xcode run the application in the simulator as you usually do.
  2. Open the maps application on macOS (for convenience I usually make a new Desktop where I have both the simulator and the map application).
  3. Inside the maps (macOS), long click on any point on the map, or search for a place to let the map draw a pin where you need it.
  4. Click on the pin, then on the information (i) icon (see image).
  5. In the up right of the information view click on the share icon.
  6. Share the location with the simulator (see image).
  7. Confirm and enjoy :)

This let you test some locations quickly, having an understanding on where geographically the location is (e.g. for testing geofencing), and deciding at runtime where to go next (e.g. for debugging and fine-tuning stuff).

Tested this on MacOS Catalina 10.15.4 and Xcode 11.4.

As of Xcode 11.6 and Swift 5.3, facility to simulate custom location has been moved from "Debug" to "Features" in iOS Simulator menu.

As of the writing of this, the location option for IOS simulator has been moved to Features -> Location -> Custom Location

As of iOS 15.2 and Xcode 13.2.2, the simulator has a configurable location.

Under the Features menu, the last entry is "Location"; this gives you a sub menu with:

None
Custom Location
City Run
City Bicycle Ride
Freeway Drive
Apple

Custom Location lets you enter a Lat/Long value. Bicycle ride, City Run, and Freeway Drive are simulation of a moving location (in Cupertino, of course).

Changing Location of simulator does not affect already built, loaded apps. For example, if you have an app with Google map view running on simulator the map won't be updated till you rebuild the app. Also, keep in mind that when entering custom lat and long you should be careful with longitudes with (-) sign and without. Replacing existing custom longitude of the simulator with new one but keeping (-) sign mistakenly or entering incorrect lat/long will result empty map screen with blue background - probably indicates oceans or poles.

In Xcode itself (not the Simulator app), a simulated location can be set via Debug menu > Simulate Location.

That menu option becomes enabled when the app is actively running (either on the Simulator, or on a real device).

XCode > Debug menu > Simulate Location > Child menu with list of locations

(As of XCode 13.0)

Related