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

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

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


当前回答

您可以通过Telnet连接到模拟器。然后你有一个模拟器控制台,允许你输入特定的数据,如地理定位,网络等。

如何使用控制台在这里有详细的解释。 要连接到控制台,打开命令行并键入

telnet localhost 5554

然后,您可以使用geo命令在设备上设置纬度、经度以及(如果需要的话)海拔高度,该设备将通过gps位置提供程序传递给所有程序。请参阅上面的链接以获得进一步的说明。

要在控制台中运行的特定命令为

geo fix <longitude value> <latitude value>

我发现这个网站对于找到一个现实的纬度/lng很有用:http://itouchmap.com/latlong.html

如果您需要多个坐标,您也可以使用带有路由的kml文件,本文对此进行了一些描述。我现在找不到更好的消息来源了。

其他回答

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

您可以通过Telnet连接到模拟器。然后你有一个模拟器控制台,允许你输入特定的数据,如地理定位,网络等。

如何使用控制台在这里有详细的解释。 要连接到控制台,打开命令行并键入

telnet localhost 5554

然后,您可以使用geo命令在设备上设置纬度、经度以及(如果需要的话)海拔高度,该设备将通过gps位置提供程序传递给所有程序。请参阅上面的链接以获得进一步的说明。

要在控制台中运行的特定命令为

geo fix <longitude value> <latitude value>

我发现这个网站对于找到一个现实的纬度/lng很有用:http://itouchmap.com/latlong.html

如果您需要多个坐标,您也可以使用带有路由的kml文件,本文对此进行了一些描述。我现在找不到更好的消息来源了。

首先进入eclipse中的DDMS部分 比打开模拟器控件.... 转到手动部分 设置纬度和长度,然后按发送按钮

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

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

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

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.