iphone - 在 Xcode 4.2 中使用 GPX 路线或轨道进行测试

标签 iphone ios core-location xcode4.2

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

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

最佳答案

最好的方法是创建您自己的模拟器类来读取文件并生成 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

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

关于iphone - 在 Xcode 4.2 中使用 GPX 路线或轨道进行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7798489/

相关文章:

iphone - NSString 真的是不可变的吗?

ios - 如何禁止某些部分在 iOS 5 中显示为 TVOut?

ios - NSInvalidArgumentException,原因 : 'Data parameter is nil'

ios - CoreLocation 闲置后停止获取更新

ios - 如何等到“当前位置”对话框得到回答才能运行方法?

iphone - CFURLCreateStringByAddingPercentEscapes 返回 NULL

ios - 如何使用尺寸等级为小型 iPhone 和 iPhone 6 进行不同的设计?

ios - Web Inspector IOS9 safari空白

ios - Firebase 消息传递仅适用于前台

iphone - 如何以编程方式为 iPhone 上的应用程序启用位置服务