Location simulation in xcode

3 min readMar 10, 2017

Suppose if your client is in another country and the app should use location services, then the only way is to simulate location.

Apple have given us the ability to simulate locations within our applications. This simulation works for both the device and the simulator.

For simulating location, goto your TargetEdit scheme .

Then under the Run scheme, select options tab. As you can see in the image below, the Allow location simulation checkbox should be enabled. Then you can choose a default location from the drop down.

Now, connect the device and then build and run the app (works also in simulator the same way.). Suppose if you choose Mumbai, India from the dropdown, then the app is virtually in India. The CLLocationManager will return you the location of Mumbai , India once location methods are being called.

Suppose the country that you want to simulate the location is not in the dropdown list, then you can create a ‘.gpx ‘ file (GPS Exchange Format) using some online websites and add it to Xcode (Just google how to create a gpx file.). You can see the Add GPX file to project option at the bottom of the dropdown in the above image.

For creating a GPX file, you can go to http://gpx-poi.com/ and simply fill the required data. You don’t have to add all the gps related data. I Just wanted the country code to be VN and the name to be Vietnam. SO add these two fields → create → download.

NOTE: creating a .gpx file is possible in xcode as well. Goto filenewfile and select gpx file. This is just an xml file with keys and values. Just add tags like name ,sym (for country symbol) etc..

Example of xml tag (for country symbol) : <sym>VN</sym>

Add the GPX file to the xcode and now, you can see the newly added location name in the list. Put a breakpoint in your app delegate application:didFinishLaunchingWithOptions: . Run the application and when the breakpoint is triggered you’ll see the Location Services icon in the jump bar of the debug area.

Select your location and then run the application and Location Services will now run through the simulated locations in the GPX file.

IMPORTANT: When you simulate a location on a device, Location Services has been hijacked until you deploy your app with location simulation turned off. Otherwise all the apps in your device will be virtually in the simulated location.

Have fun . Happy simulating !

If you enjoyed reading this post, please share and recommend it so others can find it 💚💚💚💚💚💚 !!!!