Simulating A Moving Location In iOS

Let's see how we can simulate a changing user's location with Xcode and the iOS Simulator.

While I was working at Porsche, I spent most of my time working on a new Navigation SDK. In order to successfully develop the SDK, we needed a way of simulating a user's changing location. In particular, we wanted to assess the performance of different navigation algorithms by testing them against the same set of location updates.

Fortunately, we can easily replay location updates using .gpx files in Xcode.

A .gpx file is essentially a mapping of GPS points over time; specifying a timestamp with each GPS coordinate allows you to simulate walking, biking, or driving along the highway.

Here's an example of what a .gpx file could like like (courtesy of MapBox):

<?xml version="1.0" encoding="UTF-8"?>
<gpx version="1.1" creator="Garmin Connect"
  xmlns:gpxx="" xmlns:xsi="">
    <link href="">
      <text>Garmin Connect</text>
      <trkpt lon="-77.02016168273985" lat="38.92747367732227">
      <trkpt lon="-77.02014584094286" lat="38.927609380334616">
Notice the mapping between GPS positions and time

We can create our own GPX trace using GPX Generator:

As you can see, this tool also allows us to specify the speed, which is a great convenience to have. Plus, this tool is entirely free :)

Here's what the downloaded .gpx file looks like:

<?xml version="1.0"?>
<gpx version="1.1" creator="">
<wpt lat="37.77849246241238" lon="-122.41817443121337">
<wpt lat="37.77866280032752" lon="-122.41660999231262">
<wpt lat="37.77894066029837" lon="-122.41459250450134">
<wpt lat="37.77870772846182" lon="-122.41474617094659">
<wpt lat="37.77752053479124" lon="-122.4132548627343">
<wpt lat="37.776260833361775" lon="-122.41163804122785">
<wpt lat="37.775319528789794" lon="-122.41050078460553">
<wpt lat="37.775007006940626" lon="-122.41008235999921">
<wpt lat="37.773802792942675" lon="-122.41163804122785">
<wpt lat="37.77624512200896" lon="-122.414727946013">
<wpt lat="37.77755010903112" lon="-122.4164929111987">
<wpt lat="37.77750770892152" lon="-122.41807005009946">
<wpt lat="37.778465945462955" lon="-122.41826316914853">

All we need to do now is point Xcode to the .gpx file so that every time we launch the Simulator, these coordinates will be repeated in a loop.

In your Xcode project, select your Target -> Edit Scheme. Then, in the Run -> Options tab, select the Default Location dropdown and choose "Add GPS Exchange to Project":

Now, you can pick the new .gpx file you just created.

Now, go ahead and launch your project.

Voila! The location of our user is now being simulated exactly following the custom path we provided.

If you're interested in more articles about iOS Development & Swift, check out my YouTube channel or follow me on Twitter.

If you want to be notified whenever I post a new article, join the mailing list below.

Do you have an iOS Interview coming up?

Check out my book Ace The iOS Interview!

Subscribe to Aryaman Sharda

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
[email protected]