Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GPX route or track for testing in Xcode 4.2

Has anyone had any success using a GPX route or track to test location aware apps that depend on movement in Xcode 4.2? I have been able to get it to use a single waypoint in a GPX file or even get it to iterate over a series of waypoints, but I have not been able to have it follow a track in a way that would give speed and course information. I have tried with recorded tracks from driving, hand made routes and tracks, and routes made with Trailrunner.

It may be that this functionality just is not available, but Apple does provide a freeway drive in the simulator. I want to be able to do something similar on device and in a location that I can specify. Anybody have any thoughts?

like image 245
RPeck Avatar asked Oct 17 '11 19:10

RPeck


People also ask

What is the difference between GPX route and track?

A route is a sequence of waypoints, its the plan for your navigation. A track is the recorded path you did actually follow while trying to implement the plan (the route).

How do I use GPX files in Xcode?

1) Open finder project and paste the GPX file in route directory. 2) Add that file in your project. 4) Start the simulation through GPX data.

How do I use GPX tracks?

The easiest way to open a GPX file and view the map data it contains is by uploading it to the web version of Google Maps. After you open and sign in to Google Maps in your web browser, you can add a GPX file as a new map by: Opening the Google Maps menu and selecting Your places. Selecting Maps → Create map.

What is GPX route file?

A GPX file, also known as a GPS Exchange Format file, is simply a text file with geographic information such as waypoints, tracks, and routes saved in it. You can use GPX files to transfer that information between GPS units and computers.


3 Answers

The best way is to create your own simulator class to read the file and generate CLLocation events, which gives you complete control. GPX files don't contain speed and heading, so you'll have to calculate them yourself. The basic simulation loop I've used is:

Simulate{
  if (!eof) {
    Read the next waypoint
    Calculate distance, dt (delta time), bearing and speed (distance/dt) from the previous waypoint

    Generate a CLLocation object and call the didUpdateToLocation delegate method
    Peek at the next waypoint and calculate next_dt
    Scale next_dt   // as desired for faster playback (e.g. dt/2 would be 2x)
    Start an NSTimer with next_dt as the duration
  }
}

When the timer fires, call Simulate again

Note: Until recently, synthesizing CLLocations was somewhat problematic since CLLocation is immutable and the init method had no way to set speed and heading. This was remedied in iOS 4.2.

like image 182
David Gish Avatar answered Oct 14 '22 05:10

David Gish


The Freeway Drive appears to be defined by a 1.6 MB file in /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/System/Library/Frameworks/CoreLocation.framework/Support/SimulationScenarios/Freeway Drive.plist. It's a dictionary with two keys, Options and Locations. Options itself is a dictionary with two keys and can probably be reverse engineered. Locations, on the other hand, is a large array (2240 items) of NSData, each one about 724 bytes. The first eight bytes decode to "bplist00", so each of these is a plist. I wrote one to disk, but Xcode's property list editor claims it is corrupted.

The directory where that file is is also where the other canned locations and routes live. I duplicated one of the files and restarted the simulator, and the new file showed up in the Debug menu.

The biggest issue with adding your own files is that a future Xcode update might erase them, but that's not such a big deal if you keep the originals somewhere.

like image 21
Steve Madsen Avatar answered Oct 14 '22 07:10

Steve Madsen


You can plot complex routes using Google Maps and then convert them to a compatible GPX file using https://mapstogpx.com/mobiledev.php

like image 23
Sverrir Sigmundarson Avatar answered Oct 14 '22 05:10

Sverrir Sigmundarson