Monday, 2 December 2013

iOS development: customise GPS path for Simulator

When developing location-based apps, sometimes we want to simulate a path or movements on Simulator. Xcode provides the ability to change "current user location". Rather than a single location, it can also continuously change the "current user location". And it looks like the user travels along a route. To enable this, a GPS path file is required.  Here is a way to create a path for Xcode to run after.

Step 1. Generate gpx file.
Go to http://www.bikehike.co.uk/mapview.php or some similar websites to generate a gps path file which ended with .gpx. Download it, and it shall looks like:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>

<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="bikehike.co.uk" version="1.1" 
  <metadata>
    <time>2013-12-02T12:35:19Z</time>
    <bounds minlat="-37.900140" minlon="144.662850" maxlat="-37.897000" maxlon="144.673920" /> 
  </metadata>
  <rte>
    <name>swhereTwerribee</name>
    <number>1</number>
    <rtept lat="-37.897000" lon="144.673920">
      <ele>13</ele>
      <time>2013-12-02T12:35:19Z</time>
      <name>pt0</name>
    </rtept>
...
...
...
    <rtept lat="-37.897970" lon="144.671830">
      <ele>13</ele>
      <time>2013-12-02T12:36:35Z</time>
      <name>pt1</name>
    </rtept>
  </rte>

</gpx>

Step 2. Modify the gpx file.
This format is not compatible with Xcode. So we need to do some fix. First, delete the content which is meaningless for Xcode (shown above). Then, replace all rtept with wpt . It should looks like this after modification:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" creator="bikehike.co.uk" version="1.1" 
    <wpt lat="-37.897000" lon="144.673920">
      <ele>13</ele>
      <time>2013-12-02T12:35:19Z</time>
      <name>pt0</name>
    </wpt>
...
...
...
    <wpt lat="-37.897970" lon="144.671830">
      <ele>13</ele>
      <time>2013-12-02T12:36:35Z</time>
      <name>pt1</name>
    </wpt>
</gpx>


Step 3. Load the modified gpx file to Xcode.
After launching app from Xcode and running it in Simulator, go back to Xcode and add the gpx file to your project (following graph). Then the your new location/path will be showed in this list. Click to choose it.
Step 4. Check it.
When your app is still running in Simulator, click the "home" button of your iPhone/iPad Simulator. Then open the default map app, and show the current location. The movement will be exactly the same as you made from http://www.bikehike.co.uk/mapview.php.


Something worth mention:
1. Several default movements are available from Simulator menu ->Debug->Location.
2. The speed of customised path seems possibly to be controlled by the <time> rag in gpx file? I am not sure about this. But anyway, you can set the speed when you make the path on the website.



No comments:

Post a Comment