Android模拟器中的动态地理位置更新?

时间:2012-11-02 12:04:38

标签: android android-emulator

我使用Location Manager获取当前的经度和纬度,但在模拟器中我收到错误。如何在模拟器上获取位置?

这是我的代码:

lm = (LocationManager) context
    .getSystemService(Context.LOCATION_SERVICE);
    android.location.Location currentLocation = lm
    .getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
    if (currentLocation == null)
        currentLocation = lm
        .getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (currentLocation != null) {
        currentLongitude = currentLocation.getLongitude();
        currentLatitude = currentLocation.getLatitude();

        // Get last location of driver
        lastLongitude = Double.valueOf(app.GetLongitude(context));
        lastLatitude = Double.valueOf(app.GetLatitude(context));
        distance = CommonFunctions.GetDistance(currentLongitude,
                currentLatitude, lastLongitude, lastLatitude);
}

4 个答案:

答案 0 :(得分:3)

您将在Eclipse中的DDMS透视图中找到此窗口。这样,您就可以使用各种位置值测试应用程序。

enter image description here

按照以下步骤设置模拟值:

通过

进入eclipse DDMS视角

Windows> Open Perspective>其他> DDMS(您可以键入以过滤列表)

找到“模拟器控制”选项卡

然后在位置控制框内

您可以将lat,long发送到模拟器以模拟gps更改。

如果找不到Emulator Control,只需通过以下方式打开它:

Windows> show view>其他>模拟器控制(您可以键入以过滤列表)

答案 1 :(得分:0)

在Eclipse中打开Emulator控件并在位置控件中设置lat,long

答案 2 :(得分:0)

如需解释清楚,您可以在此处查看:How to emulate GPS location in the Android Emulator?

在这篇文章中,它解释了如何处理问题!

希望这有帮助!

答案 3 :(得分:0)

首先,您必须打开模拟器控件视图(Window-> showView-> other-> 模拟器控件)。 然后,当您的应用程序启动时,在模拟器控件中的位置控件中, 设置位置并单击发送按钮

相关问题