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

其他回答

把阿尔贝托·高纳的回答写在一行里

token=$(cat ~/.emulator_console_auth_token); cat <(echo -e "auth $token \n  geo fix 96.0290791 16.9041016  \n exit") - | nc localhost 5554

5554是adb设备中显示的模拟器端口号。

如果亚行的emu能够发挥作用,情况会更好。

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

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

下面的解决方案对我有用——打开命令行,然后写:

adb emu geo fix [longtitude] [latitude]

在模拟中选择扩展控件。之后,您可以通过搜索或拖动映射到要设置的位置来设置模拟的位置。

最后点击SET LOCATION按钮保存。