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;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…