Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

I'm using the following GPX file in Xcode 4.2 to simulate a location change. It works well, but I can't control the speed of the location change. stamp seems to be not working. Does anyone have a solution for this?

<?xml version="1.0"?> <gpx version="1.1" creator="Xcode">      <wpt lat="37.331705" lon="-122.030237"></wpt>     <wpt lat="37.331705" lon="-122.030337"></wpt>     <wpt lat="37.331705" lon="-122.030437"></wpt>     <wpt lat="37.331705" lon="-122.030537"></wpt> </gpx> 
like image 961
lichen19853 Avatar asked Feb 24 '12 23:02

lichen19853


1 Answers

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; } 
like image 95
BB9z Avatar answered Nov 07 '22 06:11

BB9z