我想在Android模拟器中获得经度和纬度进行测试。
有谁能指导我如何实现这个目标吗?
如何将模拟器的位置设置为测试位置?
我想在Android模拟器中获得经度和纬度进行测试。
有谁能指导我如何实现这个目标吗?
如何将模拟器的位置设置为测试位置?
当前回答
对不起,在这个问题上的一些建议之后,我把我的位置设置为阿拉斯加。然而,我的设备仍然显示在加州山景城(谷歌的总部?)下面是我的修复方法:
1)进入位置设置:
2)设置测试地点。我选择了阿拉斯加。
3)谷歌“我的当前位置”,然后点击图中圈出的地图。 请注意,即使我将位置设置为阿拉斯加,我的虚拟设备仍然认为它在加州山景城。
4)点击该位置图标 您的位置现在应该在您的设备上更新。 你可以再次用谷歌搜索“我的当前位置”来验证。
如果有人遇到同样的问题,我希望我的解决方案能帮助到你。
其他回答
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
假设你已经设置并运行了mapview:
MapView mapView = (MapView) findViewById(R.id.mapview);
final MyLocationOverlay myLocation = new MyLocationOverlay(this, mapView);
mapView.getOverlays().add(myLocation);
myLocation.enableMyLocation();
myLocation.runOnFirstFix(new Runnable() {
public void run() {
GeoPoint pt = myLocation.getMyLocation();
}
});
您需要在清单中获得以下许可:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
要从Eclipse向模拟器发送模拟坐标,请转到“窗口”菜单,选择“显示视图”>“其他”>“模拟器控件”,您可以从出现的模拟器控制窗格中发送坐标。
如果你正在使用eclipse,然后使用模拟器控制器,你可以手动设置纬度和经度,并在模拟器中运行基于地图的应用程序
在Linux系统中,通信端口被阻塞。导航终端到android SDK中的platform-tools文件夹,并启动以下命令:
./adb -s #{device_name} emu geo fix #{longitude} #{latitude}