使用GPX路由或跟踪在Xcode 4.2中进行测试

RPe*_*eck 10 iphone core-location ios xcode4.2

有没有人使用GPX路线或轨道来测试依赖于Xcode 4.2移动的位置感知应用程序?我已经能够让它在GPX文件中使用单个航点,或者甚至让它在一系列航路点上进行迭代,但是我无法让它按照提供速度和航线信息的方式跟踪航迹.我尝试过用驾驶,手工制作的路线和轨道记录的轨道,以及用Trailrunner制作的路线.

可能这个功能不可用,但Apple确实在模拟器中提供了高速公路驱动器.我希望能够在设备上以及我可以指定的位置执行类似的操作.有人有什么想法吗?

Dav*_*ish 4

最好的方法是创建您自己的模拟器类来读取文件并生成 CLLocation 事件,这样您就可以完全控制。GPX 文件不包含速度和航向,因此您必须自己计算它们。我使用的基本模拟循环是:

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
Run Code Online (Sandbox Code Playgroud)

注意:直到最近,合成 CLLocation 还存在一些问题,因为 CLLocation 是不可变的,并且 init 方法无法设置速度和航向。iOS 4.2 中修复了这个问题。