eclipse 无法在 Android 模拟器中模拟位置数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25953054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 22:00:13  来源:igfitidea点击:

Unable to simulate location data in Android emulator

androideclipseandroid-emulatorgeolocationavd

提问by emersonthis

I'm trying to test my app, which uses geolocation using the emulator. Several methods are described here. I'm going to Window->Open Perspective->DDMS, then entering lat. and long. one in Location Controlsand then I hit "Send".

我正在尝试使用模拟器测试我的应用程序,该应用程序使用地理定位。这里描述几种方法。我要去Window->Open Perspective->DDMS,然后进入纬度。和长。一个,Location Controls然后我点击“发送”。

enter image description here

在此处输入图片说明

But it doesn't work. Instead I see the following error: Unable to send command to the emulator.

但它不起作用。相反,我看到以下错误:Unable to send command to the emulator.

Why is this happening!?

为什么会这样!?

I don't think my app is the problem because I tested with the emulator's default browser and it also cannot access location info.

我不认为我的应用程序有问题,因为我使用模拟器的默认浏览器进行了测试,它也无法访问位置信息。

Details:

细节:

  • OSX 10.9.4
  • AVD_for_Nexus_4_by_Google targeting v4.4.2
  • Eclipse IDE for Android Developers 23.0.2.1259578
  • OSX 10.9.4
  • AVD_for_Nexus_4_by_Google 定位 v4.4.2
  • 面向 Android 开发人员的 Eclipse IDE 23.0.2.1259578

Update:I changed to AVD_for_Galaxy_Nexus_by_Googleand it still doesn't work, but I no longer see that error. I click send and nothing happens.

更新:我更改为AVD_for_Galaxy_Nexus_by_Google它仍然不起作用,但我不再看到该错误。我点击发送,没有任何反应。

Update2:I've tested using Telnet to pass location data to the emulator, and again nothing happens. No errors. Just nothing. Urgh!

更新 2:我已经测试过使用 Telnet 将位置数据传递给模拟器,但再次没有任何反应。没有错误。根本不值一提。呃!

telnet localhost 5554
geo fix 50 50

It responds with OKbut nothing happens. Still no location data available.

它响应OK但没有任何反应。仍然没有可用的位置数据。

Update3:I notice a stream of the following errors in LogCat

更新 3:我注意到 LogCat 中的以下错误流

09-20 17:58:59.910: E/eglCodecCommon(1777): glUtilsParamSize: unknow param 0x00000b44
09-20 17:58:59.910: E/eglCodecCommon(1777): glUtilsParamSize: unknow param 0x00000bd0
09-20 17:58:59.930: E/eglCodecCommon(1777): **** ERROR unknown type 0x0 (glSizeof,72)

The app seems to be running fine, and these errors are supposedly explained here.

该应用程序似乎运行良好,这些错误应该在这里解释。

Update 4:I've seen multiple suggestions to confirm that my AVD has GPS Support enabled, but this option/setting does not appear anywhere. When I open the "Android Virtual Device Manager" and then click "Edit" on one of my devices, this is what I see: enter image description here

更新 4:我已经看到多个建议来确认我的 AVD 已启用 GPS 支持,但此选项/设置并未出现在任何地方。当我打开“Android 虚拟设备管理器”,然后在我的一台设备上单击“编辑”时,我看到的是: 在此处输入图片说明

No mention of "GPS Support".

没有提到“GPS 支持”。

Update 5:I checked the config.ini file for all my AVDs and they are all correctly set to hw.gps=yes. I also created an AVD using a Google API target, however I'm still having the same problem. The app loads but no location data is available, with "Location Controls" as well as telnet.

更新 5:我检查了所有 AVD 的 config.ini 文件,它们都正确设置为hw.gps=yes. 我还使用 Google API 目标创建了一个 AVD,但是我仍然遇到同样的问题。该应用程序加载但没有位置数据可用,具有“位置控制”以及 telnet。

Update 6:Following Gyebro's suggestions below... trying to load his LocationDemo app... enter image description here

更新 6:按照下面 Gyebro 的建议......尝试加载他的 LocationDemo 应用...... 在此处输入图片说明

Here's what I see in the LogCat:

这是我在 LogCat 中看到的:

回答by Gyebro

To check whether your emulator supports GPS, go to ~/.android/avd/<emulatorname>.avd/and check config.iniand hardware-qemu.ini(if exists) they should contain:

要检查您的模拟器支持GPS是否去~/.android/avd/<emulatorname>.avd/检查config.inihardware-qemu.ini(如果存在的话)应包含以下内容:

hw.gps = yes

hw.gps = 是

EDIT
You must use a Google APIs system image. You should set Google APIs - API Level 1#as target

编辑
您必须使用 Google API 系统映像。你应该设置Google APIs - API Level 1#为目标

End of EDIT

编辑结束

Assuming this is so, and Location is enabled in your emulator, run this test application in your emulator: LocationTest demo, for details see the Dev docs on Retrieving the Current Location

假设是这样,并且在您的模拟器中启用了 Location,请在您的模拟器中运行此测试应用程序:LocationTest demo,有关详细信息,请参阅有关检索当前位置开发文档

This sample implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListenerand LocationListener. And also checks for Google Play Services before connecting with the LocationClient (that's why we needed a GoogleEmulator image.) (See MainActivity.java)

此示例实现GooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListenerLocationListener。并且在连接 LocationClient 之前检查 Google Play 服务(这就是我们需要GoogleEmulator 图像的原因。)(参见MainActivity.java

After you start the app, you should see the Location icon in the status bar. Also verify, that the GP Services are present and the LocationClient is connected in the Log.

启动应用程序后,您应该会在状态栏中看到位置图标。还要验证 GP 服务是否存在并且 LocationClient 是否已在日志中连接。

 D/LocationTest﹕ Google Play services is available.
 D/LocationTest﹕ LocationClient: Connected

After sending geo fix 66 80using telnet (should respond with OK) or other validcoordinates using DDMS, you should see:

geo fix 66 80使用 telnet(应以 响应OK)或使用 DDMS 的其他有效坐标发送后,您应该看到:

 D/LocationTest﹕ Location changed!

If you are still lost with this approach, another way to simulate locations is to create a Mock Location Provider app.

如果您仍然对这种方法感到迷惑,另一种模拟位置的方法是创建一个 Mock Location Provider 应用程序

回答by Eefret

You really should use GENYMOTIONit offers a GPS feature in which u set the location coordinates, plus it's faster than the default emulator and works fine in almost every OS, heres the Docus on how to apply that GPS stuff hereinside that page look for "GPS widget". Good luck.

你真的应该使用GENYMOTION它提供了GPS功能,其中U设置的位置坐标,再加上它比默认的仿真器速度更快,几乎在每一个操作系统工作正常,继承人的Docus上如何应用GPS的东西在这里该页面查找内部“ GPS 小部件”。祝你好运。

Heres a shot from that window

这是从那个窗口拍的

genymotino gps widget

genymotino GPS 小部件

回答by ashoke

I tried with latest SDK and adb tools, i see the same problem with Google Maps and web browser based location (maps.google.com). I used adb command line as well as telnet methods to set the location. Also verified my .avd file has hw.gps=yes(which is set by default). I even tried with older Google API images. I made sure to try out different accuracy levels too - device only, high accuracy etc. I notice lot of graphics rendering issues and quite a few opengl error messages in logcat, similar to ones you see.

我尝试使用最新的 SDK 和 adb 工具,但我发现 Google 地图和基于网络浏览器的位置 (maps.google.com) 也存在同样的问题。我使用 adb 命令行以及 telnet 方法来设置位置。还验证了我的 .avd 文件hw.gps=yes(默认设置)。我什至尝试过使用较旧的 Google API 图像。我也确保尝试不同的精度级别 - 仅设备,高精度等。我注意到很多图形渲染问题和 logcat 中的很多 opengl 错误消息,与您看到的类似。

I did get google maps app to work on Android emulator using mock locations feature. You can use mock locations on a real device too, which i prefer for its performance. For details on how to use mock location please see this.. Download the zip file which has LocationProvider project , that lets you simulate different location and movement scenarios.

我确实让谷歌地图应用程序使用模拟位置功能在 Android 模拟器上工作。您也可以在真实设备上使用模拟位置,我更喜欢它的性能。有关如何使用模拟位置的详细信息,请参阅此处。. 下载包含 LocationProvider 项目的 zip 文件,它可以让您模拟不同的位置和移动场景。

so you can pick:

所以你可以选择:

  • Use a physical android device with mock locations feature
  • If you want to use emulator, try with mock locations
  • I had success with genymotion too, you can set any location you want from command line genyshellthat comes with genymotion

    genyshell.exe -c "gps setstatus enabled" genyshell.exe -c "gps setlatitude 30.3077609" genyshell.exe -c "gps setlongitude -97.7534014"

  • 使用具有模拟位置功能的物理安卓设备
  • 如果您想使用模拟器,请尝试使用模拟位置
  • 我在 genymotion 上也取得了成功,您可以从genyshellgenymotion 附带的命令行中设置您想要的任何位置

    genyshell.exe -c "gps setstatus enabled" genyshell.exe -c "gps setlatitude 30.3077609" genyshell.exe -c "gps setlongitude -97.7534014"

device is preferable for performance reasons.

出于性能原因,设备是首选。

Update:I tested with LocationTest demo by gyebroand it works when i set the location params using telnet. So the problem seems to be with google maps or browser and not with emulator or adb tools. location test demo

更新:我使用gyebro 的 LocationTest 演示进行了测试,当我使用 telnet 设置位置参数时它可以工作。所以问题似乎出在谷歌地图或浏览器上,而不是模拟器或 adb 工具上。 定位测试演示

回答by noni

Did you tried with free version of Genymotion? It works as a real device connected by USB, and it can create GPS positions as you need. I know that this is not a solution for your AVD problem but AVD is in generally a poor solution to Android testing on emulators.

您是否尝试过免费版的Genymotion?它作为通过 USB 连接的真实设备工作,可以根据需要创建 GPS 位置。我知道这不是您的 AVD 问题的解决方案,但 AVD 通常是在模拟器上进行 Android 测试的糟糕解决方案。

It's free if you want to test this function specifically.

如果您想专门测试此功能,它是免费的。

回答by Gustavo Baiocchi Costa

I was running through the same errors. The problem was that the AVD DDMS uses a comma instead of a dot in their location coordinates.

我遇到了同样的错误。问题是 AVD DDMS 在其位置坐标中使用逗号而不是点。

Use LAT: -16,691534 LNG: -49,266185 something like this and you will be fine!

使用 LAT:-16,691534 LNG:-49,266185 类似的东西,你会没事的!

回答by Sandeep Kumar

Make sure your AVD has GPS support hardware set to true

确保您的 AVD 将 GPS 支持硬件设置为 true

Create New AVD > Hardware > New > GPS support

创建新的 AVD > 硬件 > 新建 > GPS 支持

Value should be "yes"

值应该是“是”

Also, ensure your app is requesting location updates in some way, otherwise the emulator will just ignore any incoming locations from DDMS or the console.

此外,请确保您的应用以某种方式请求位置更新,否则模拟器将忽略来自 DDMS 或控制台的任何传入位置。

(or)

(或者)

I just use the android console via telnet, it always works.

我只是通过 telnet 使用 android 控制台,它总是有效。

Just open a command line and:

只需打开一个命令行,然后:

telnet localhost 5554

5554 is the port number of your emulator, it is usually that but might change, it can be on the window fram of the emulator as PORT:AVD_NAME.

5554 是你的模拟器的端口号,它通常是但可能会改变,它可以作为 PORT:AVD_NAME 在模拟器的窗口框架上。

You should be greeted with an Android console message.

您应该会收到一条 Android 控制台消息。

To send positions to your device just type.

要将位置发送到您的设备,只需键入。

geo fix []

Two valid statements would be

两个有效的陈述是

geo fix -77.036519 38.896143
geo fix -77.036519 38.896143 100

Hope this helps, its not DDMS, but it works always. You can also feed it nmea sentences but I dont think you need that.

希望这会有所帮助,它不是 DDMS,但它始终有效。你也可以给它提供 nmea 句子,但我认为你不需要那个。