When using GPX in Xcode to simulate location changes, is there a way to control the speed? When using GPX in Xcode to simulate location changes, is there a way to control the speed? ios ios

When using GPX in Xcode to simulate location changes, is there a way to control the speed?


Xcode support simulate speed change with a GPX file.

Provide one or more waypoints containing a latitude/longitude pair. If you provide one waypoint, Xcode will simulate that specific location. If you provide multiple waypoints, Xcode will simulate a route visitng each waypoint.

Optionally provide a time element for each waypoint. Xcode will interpolate movement at a rate of speed based on the time elapsed between each waypoint. If you do not provide a time element, then Xcode will use a fixed rate of speed. Waypoints must be sorted by time in ascending order.

Write like this:

<wpt lat="39.96104510" lon="116.4450860">    <time>2010-01-01T00:00:00Z</time></wpt><wpt lat="39.96090940" lon="116.4451400">    <time>2010-01-01T00:00:05Z</time></wpt>...<wpt lat="39.96087240" lon="116.4450430">    <time>2010-01-01T00:00:09Z</time></wpt>

About -1 speed

The CoreLocation object’s speed will always be -1 during simulation. A possible workaround is save a last location then calculate the speed ourselves. Sample code:

CLLocationSpeed speed = location.speed;if (speed < 0) {    // A negative value indicates an invalid speed. Try calculate manually.    CLLocation *lastLocation = self.lastLocation;    NSTimeInterval time = [location.timestamp timeIntervalSinceDate:lastLocation.timestamp];    if (time <= 0) {        // If there are several location manager work at the same time, an outdated cache location may returns and should be ignored.        return;    }    CLLocationDistance distanceFromLast = [lastLocation distanceFromLocation:location];    if (distanceFromLast < DISTANCE_THRESHOLD        || time < DURATION_THRESHOLD) {        // Optional, dont calculate if two location are too close. This may avoid gets unreasonable value.        return;    }    speed = distanceFromLast/time;    self.lastLocation = location;}


I don't think you can do it with GPX files. But it is easy with Automation tool within Intruments. Here is one of the scripts I use myself for my app testing and screenshots gathering:

var target = UIATarget.localTarget();// speed is in meters/secvar points = [          {location:{latitude:48.8899,longitude:14.2}, options:{speed:8, altitude:200, horizontalAccuracy:10, verticalAccuracy:15}},          {location:{latitude:48.8899,longitude:14.9}, options:{speed:11, altitude:200, horizontalAccuracy:10, verticalAccuracy:15}},          {location:{latitude:48.8899,longitude:14.6}, options:{speed:12, altitude:200, horizontalAccuracy:10, verticalAccuracy:15}},          {location:{latitude:48.8899,longitude:14.7}, options:{speed:13, altitude:200, horizontalAccuracy:10, verticalAccuracy:15}},          {location:{latitude:49.2,longitude:14.10}, options:{speed:15, altitude:200, horizontalAccuracy:10, verticalAccuracy:15}},          {location:{latitude:49.4,longitude:14.8}, options:{speed:15, altitude:200, horizontalAccuracy:10, verticalAccuracy:15}},          {location:{latitude:48.8899,longitude:14.9}, options:{speed:9, altitude:200, horizontalAccuracy:10, verticalAccuracy:15}},          {location:{latitude:48.8899,longitude:15.1}, options:{speed:8, altitude:200, horizontalAccuracy:10, verticalAccuracy:15}},          {location:{latitude:48.8899,longitude:16.1}, options:{speed:3, altitude:200, horizontalAccuracy:10, verticalAccuracy:15}},          ];for (var i = 0; i < points.length; i++){target.setLocationWithOptions(points[i].location,points[i].options);target.captureScreenWithName(i+"_.png");target.delay(1.0);}

I created step by step walkthrough for how I used location simulation with Automation and Leaks to grab screenshots and find leaks


I don't think (know) that this is possible in the GPX directly, but you can test location change with Instruments/Automation.

You'd use a script like:

var target = UIATarget.localTarget();target.setLocation(<location);target.delay(5);target.setLocation(...);

And so on. I took this example from the WWDC11 video (Testing your location-aware applications)

I'm aware that this doesn't actually let you define the speed, but the delays somehow account for that I hope. Maybe that'll help you.