我想在Android模拟器中获得经度和纬度进行测试。
有谁能指导我如何实现这个目标吗?
如何将模拟器的位置设置为测试位置?
我想在Android模拟器中获得经度和纬度进行测试。
有谁能指导我如何实现这个目标吗?
如何将模拟器的位置设置为测试位置?
当前回答
对于Android Studio用户:
运行模拟器,
然后进入“工具->Android ->Android设备监视器”
打开模拟器控件选项卡,并使用位置控件组。
其他回答
如果上述解决方案不奏效。试试这个:
在你的android manifest .xml中,在应用程序标记之外添加以下两个链接,当然是在你的manifest标记中
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" ></uses-permission>
<uses-permission android:name="android.permission.INTERNET" ></uses-permission>
对于新的模拟器:
http://developer.android.com/tools/devices/emulator.html#extended
基本上,点击模拟器控件中的三个点按钮(模拟器的右侧),它将打开一个菜单,允许你控制模拟器,包括位置
打开Android studio->工具菜单->Android-> Android设备监视器->模拟器选项卡->位置控制->设置所需的纬度和经度,并根据需要检查项目
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.
我已经做了一个类似于前面的答案之一的小脚本,但使用expect而不是python -因为它更简单一点(expect是为此而发明的)。
#!/usr/bin/expect
set port [lindex $argv 0]
set lon [lindex $argv 1]
set lat [lindex $argv 2]
set timeout 1
spawn telnet localhost $port
expect_after eof { exit 0 }
## interact
expect OK
set fp [open "~/.emulator_console_auth_token" r]
if {[gets $fp line] != -1} {
send "auth $line\r"
}
send "geo fix $lon $lat\r"
expect OK
send "exit\r"
示例用法:sendloc 5554 2.35607 48.8263