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

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

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


当前回答

在Mac、Linux或Cygwin系统下:

echo 'geo fix -99.133333 19.43333 2202' | nc localhost 5554

这样你就能到墨西哥城了。相应地改变你的经度/纬度/高度。如果你对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.

对不起,在这个问题上的一些建议之后,我把我的位置设置为阿拉斯加。然而,我的设备仍然显示在加州山景城(谷歌的总部?)下面是我的修复方法:

1)进入位置设置:

2)设置测试地点。我选择了阿拉斯加。

3)谷歌“我的当前位置”,然后点击图中圈出的地图。 请注意,即使我将位置设置为阿拉斯加,我的虚拟设备仍然认为它在加州山景城。

4)点击该位置图标 您的位置现在应该在您的设备上更新。 你可以再次用谷歌搜索“我的当前位置”来验证。

如果有人遇到同样的问题,我希望我的解决方案能帮助到你。

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

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

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模拟器,点击菜单按钮(3点)如下所示:

然后在左侧窗格中,选择Location并根据需要更改坐标。按下发送按钮后,更改将立即生效(建议大家打开谷歌Maps以便更好地理解)。

Android Studio版本:2.3.3

此外,为了使不同的位置实时到达应用程序,可以使用GPX文件。从谷歌地图方向创建这个文件非常简单:

进入谷歌地图,选择一个位置,然后按“方向”进入第二个位置。 创建路由后,从浏览器复制一个链接 访问这个网站:https://mapstogpx.com,并将链接粘贴到“Let's Go”框 按下“Let's Go”键,即可下载GPX文件

使用“加载GPS/KML”按钮将创建的文件加载到模拟器中,选择速度,并按底部的绿色播放按钮。如下图所示,位置将实时发送。