我想在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.

其他回答

最后,随着Android Studio 4的最新版本和2019年10月23日他的新模拟器更新,这变得更容易了。 启动模拟器,进入模拟器参数…>在“路线”选项卡,你可以选择地图上的两个点,从/到,开始一个新的路线,播放速度可调,可以达到1000公里/小时以上!

Android Studio有一个名为“Mock Location plugin”的插件。 你可以用这个插件模拟多个点。 你可以在这个链接中找到详细的使用手册:Android Studio。用模拟位置插件模拟多个GPS点

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

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

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

假设你已经设置并运行了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向模拟器发送模拟坐标,请转到“窗口”菜单,选择“显示视图”>“其他”>“模拟器控件”,您可以从出现的模拟器控制窗格中发送坐标。

在Linux系统中,通信端口被阻塞。导航终端到android SDK中的platform-tools文件夹,并启动以下命令:

./adb -s #{device_name} emu geo fix #{longitude} #{latitude}