我在 Xcode 4.2 中使用以下 GPX 文件来模拟位置更改。效果很好,但我无法控制位置变化的速度。邮票似乎不起作用。有人有解决方案吗?
<?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>
Xcode 支持使用 GPX 文件模拟速度变化。
提供一个或多个包含一对纬度/经度的航路点。如果您提供一个路径点,Xcode 将模拟该特定位置。如果您提供多个航点,Xcode 将模拟访问每个航点的路线。
可以选择为每个航路点提供时间元素。 Xcode 将根据每个航路点之间经过的时间以一定的速度插值运动。如果您不提供时间元素,那么 Xcode 将使用固定的速度。航点必须按时间升序排序。
像这样写:
<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>
大约-1速度
在模拟过程中,CoreLocation 对象的速度始终为 -1。一种可能的解决方法是保存最后的位置,然后自己计算速度。示例代码:
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;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)