Adding Custom Locations for iOS Simulator Testing

Most of the time if you use the Core Location services in the iOS simulator it will default to Cupertino, but there are times that it will give you a kCLErrorDomain code of 0, or you may want a different location for testing. It turns out that if you edit the run scheme of your project, you can choose whether to allow location simulation and there is a drop down of predefined locations.

Screen shot showing default location setting in Edit Scheme

But what if you want a location that isn’t in the list? It turns out that there is an option for adding a GPX file to the workspace. Just get the latitude and longitude of the location you want to use (Google Maps is good for this). Then head over to GPS Visualizer. Plug in your data and ask for a GPX format file as shown below:

Screen shot showing conversion to GPX

You definitely need the “header” lines in the “paste your data here” box, otherwise the service doesn’t know what your data means. For the example above, I used OPI’s home city of Minneapolis, Minnesota.

Now you can choose to import this file from the Options panel in Edit Schemes and presto! You can now test your application in the simulator and have it give you the current location you want.

As a bonus, here’s the GPX file for Minneapolis. Enjoy!

<!--?xml version="1.0"?-->
<gpx creator="GPS Visualizer http://www.gpsvisualizer.com/" version="1.1" xmlns="http://www.topografix.com/GPX/1/1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<wpt lat="44.9833" lon="-93.2667">
  <name>Minneapolis, MN</name>
  <desc>Minneapolis, MN</desc>
</wpt>
</gpx>

About the Author

Steve McCoole profile.

Steve McCoole

Principal Technologist

Steve is a Principal Technologist for Mobile Development at Object Partners where he has been focusing on developing an enterprise mobile development practice, delivering applications to client that include: Oracle Retail, The Tile Shop, St. Jude Medical, SICK USA and Donaldson Corporation.  He has over 32 years of experience developing solutions from embedded, mobile and large-scale Java Enterprise web applications for diverse clients including IBM, Sun, Novell, Best Buy and Thomson Reuters.

One thought on “Adding Custom Locations for iOS Simulator Testing

  1. Ryo SongZi says:

    Hi
    Your guide is general method for developer.
    I think all developer know this method.

    Do you know how to simulate current location programmatically without using Xcode in swift?

    I hope you can help me.
    Best regards!

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Blog Posts
Why we started using JSON Schema in our internal Helm charts
Helm 3 supports validating the provided chart values against a JSON Schema. While it may be quicker to get started in your chart development without a schema, we found it valuable for a number of […]
Rewriting files in Google Cloud Storage
Rewriting Files in GCP Note: even though this code is in Python, this should be the same idea in JavaScript, Go, etc. I wrote the following to copy a file from one Google Cloud Storage […]
Interpreting Spatial Data in the Age of COVID-19
As 2020 has come to an end, many are eager to leave the mess of COVID-19 behind with the new year and gain a fresh start. Unfortunately, new cases are still soaring across the United […]
Building a Better Mousetrap
Recently, my daughter (age 6) was into building “mousetraps” out of shoe boxes. These were more or less comfortable cardboard mouse houses complete with beds, rooms, everything a mouse could want or need and not […]