我想在Android模拟器中获得经度和纬度进行测试。

有谁能指导我如何实现这个目标吗?

如何将模拟器的位置设置为测试位置?


当前回答

首先进入eclipse中的DDMS部分 比打开模拟器控件.... 转到手动部分 设置纬度和长度,然后按发送按钮

其他回答

如果上述解决方案不奏效。试试这个:

在你的android manifest .xml中,在应用程序标记之外添加以下两个链接,当然是在你的manifest标记中

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" ></uses-permission>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>

在模拟器控制台中使用"geo"命令

从命令行发送模拟位置数据:

在Android模拟器中启动你的应用程序,在SDK的/tools目录中打开一个终端/控制台。 连接到模拟器控制台: telnet localhost 5555(将5555替换为模拟器正在运行的任何端口) 发送位置数据: * geo fix发送固定的地理位置。 该命令接受以十进制为单位的经度和纬度,以及以米为单位的可选海拔。例如: 地理修正-121.45356 46.51119 4392

在我自己的一个项目中,我开发了一个在线服务,可以为Android模拟器提供模拟位置。

它使用geo nmea而不是geo fix,这使得它可以设置速度,航线,精确的时间等,除了纬度/长度。

该服务只需要nc (netcat)命令行工具,不需要其他工具。

http://www.kisstech.ch/nmea/

首先进入eclipse中的DDMS部分 比打开模拟器控件.... 转到手动部分 设置纬度和长度,然后按发送按钮

The already mentioned multiple times answer to use the shell command "geo fix..." is the correct answer. But in case you use LocationClient.getLastLocation() to retrieve your data it is worth to mention that it will not work at first. The LocationClient class uses the Google Play Service to retrieve the coordinates. For me this started working after running the emulators maps app once. During the first start you are asked to allow google apps access to your location, which I guess does the trick.