在 Android 中测试 GPS
如何在 Android 中测试 GPS 应用程序?我们可以使用 Android 模拟器 对其进行测试吗?
How do you test GPS applications in Android? Can we test it using the Android emulator?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
是的。
如果您使用 Eclipse ADT 插件进行开发,请在启动模拟器后打开 DDMS 透视图并查找 Emulator Control 视图。有一个位置控制部分,允许您发送固定的纬度和经度坐标,如果您想定期发送多个坐标(以模拟特定路线),则可以发送 GPX(GPS 交换格式)或 KML(Keyhole 标记语言)文件。
或者,您可以简单地 telnet 到模拟器并从命令行使用 geo 命令,它支持固定的纬度和经度坐标以及 NMEA 数据语句:
Yes.
If you develop using the Eclipse ADT plugin, open the DDMS perspective after launching the emulator and look for the Emulator Control view. There is a location controls section that allows you to send fixed latitude and longitude coordinates, or GPX (GPS Exchange Format) or KML (Keyhole Markup Language) files if you want to send multiple coordinates at regular intervals (to simulate traveling a specific route).
Alternatively, you can simply telnet to the emulator and use the geo command from the command line, which supports fixed latitude and longitude coordinates as well as NMEA data sentences:
也许您想使用单元测试,所以您可以尝试以下操作:
为此,您还需要 AndroidManifest.xml 所需的权限:
Maybe you want to a use a Unit test, so you can try this:
For this to work you also need a required permission to the AndroidManifest.xml:
也许这个测试应用程序或这个可以帮助你。
Perhaps this test application or this can help you.
除了 Mallox 代码之外,这是除了真实 GPS 位置之外的模拟位置的解决方案:
一个字符串,
TEST_MOCK_GPS_LOCATION 是测试类中的
它是: }
希望对您有帮助
in addition to Mallox code this is the sulotion for mock location in addition to real gps location :
TEST_MOCK_GPS_LOCATION is a string
in the test class it is :
}
hope it will help you
在模拟器的扩展控件中(单击模拟器旁边的控制栏上的“...”)有“位置”选项卡,您可以在其中手动输入各个位置(纬度/经度/海拔)并将其发送到虚拟模拟器设备,或从可导入的 GPX 或 KML 文件中以所需速度设置 GPS 数据播放。
编辑:这是我所说的默认 Android 模拟器。
In the Extended controls of your emulator (click "..." on the control bar next to your emulator) there is the Location tab, where you can either manually input individual locations (latitude / longitude / altitude) and send them to the virtual device, or setup GPS data playback at a desired speed from a GPX or a KML file you can import.
Edit: it's the default Android Emulator I'm talking about.
我建议您编写测试,将位置对象发送到您要测试的侦听器类。考虑到这一点,您将需要一些能够生成位置对象的辅助方法。
例如:
首先您发送一个具有固定坐标的位置(例如纽约中心)。
// 测试一切是否正常
然后发送一个距第一个坐标 100m 的坐标。您可以使用我最近实现的功能来做到这一点: https://stackoverflow.com/a/17545955/322791
// test如果一切正常
GPS 方法与时间相关是很常见的。我建议您在侦听器类上实现 getNow() 方法,并在需要当前时间时调用它。
在单元测试环境中,您只需将 obj.isUnitTesting=true 和 obj.unitTestTime 设置为您想要的任何时间。之后,您可以将第一个位置发送给侦听器,然后更改时间(+x 秒)并发送另一个位置...
以这种方式测试您的应用程序会更容易。
I suggest that you write test which is sending location object to the listener class you want to test. With this in mind you will need some helper methods that will be able to produce location objects.
E.g.:
First you send a location with fixed coordinates (e.g. center of New York).
// test if everything is OK
Than you send a coordinate which is 100m appart from the first coordinate. You can do this with function I implemented recently: https://stackoverflow.com/a/17545955/322791
// test if everything is OK
It is common that GPS methods are related to time. I suggest that you implement method getNow() on listener class and call it whenever you need current time.
In unit test environment you simply set the obj.isUnitTesting=true and obj.unitTestTime to any time you want. After that you can send first location to the listener, then you change time (+x seconds) and send another location ...
It will be much easier to test your application that way.