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

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

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


当前回答

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

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

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

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

其他回答

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

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

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

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

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.

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

我在Android studio 3.5.1上也遇到了同样的问题 当我点击android模拟器右边的三个点并选择位置选项卡时,我没有看到发送选项。我试图设置一个位置点,但这没有改变我的默认库比蒂诺位置。 打开谷歌地图,它会自动定位你和你的库比蒂诺的位置会改变。

对于Android Studio用户:

运行模拟器,

然后进入“工具->Android ->Android设备监视器”

打开模拟器控件选项卡,并使用位置控件组。