在 iPhone 模拟器上测试 CoreLocation [英] Testing CoreLocation on iPhone Simulator

查看:22
本文介绍了在 iPhone 模拟器上测试 CoreLocation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新: 从 iOS 5 和 Xcode 4.1 开始,现在可以在模拟器中测试位置,甚至定义路线.有关详细信息,请参阅 http://developer.apple.com.

遗留问题

有没有办法在 iPhone 模拟器上测试 CoreLocation?

我所需要的只是能够自己设置位置并让 CoreLocation 返回它.

解决方案

感谢您的宝贵反馈,它促使我找到了一个可靠的解决方案.

所有代码都可以在这里找到:

http://code.google.com/p/dlocation/

非常凌乱,但随着我使用它,它会变得更好.

解决方案是继承CLLocationManager 并定义一个新的委托@protocol,称为DLocationManagerDelegate.

它被设计为 CLLocationManagerDelegate 的简单替代品,当部署在实际设备上时,它编译成一个非常的薄层.

在设备上运行时,它将使用 CoreLocation 正常返回数据,但在模拟器中,它将从文本文件(在 DLocationManager.h 文件中定义)读取纬度和经度.

我希望这会有所帮助,实现很简单,您必须startUpdatingLocationstopUpdatingLocation 来更新显示.

我们将不胜感激地收到评论和反馈.

UPDATE: As of iOS 5 and Xcode 4.1 is is now possible to test location in the simulator and even define routes. See http://developer.apple.com for more details.

Legacy Question

Is there anyway to test CoreLocation on the iPhone Simulator?

All I require is to be able to set the location myself and have CoreLocation return it.

解决方案

Thanks for the great feedback, it has prompted me to find a robust solution.

All the code can be found here:

http://code.google.com/p/dlocation/

It is very messy but as I use it it will be become much better.

The solution was to subclass CLLocationManager and define a new delegate @protocol, called DLocationManagerDelegate.

It is designed to be a simple drop-in replacement for CLLocationManagerDelegate that compiles down to a very thin layer when deployed on an actual device.

When running on the device it will return data as normal using CoreLocation, but in the simulator it will read latitude and longitude from a text file (defined in the DLocationManager.h file).

I hope this helps, the implementation is on the simple side and you have to startUpdatingLocation and stopUpdatingLocation to update the display.

Comments and feedback will be gratefully received.

这篇关于在 iPhone 模拟器上测试 CoreLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆