Unable to simulate location data in Android emulator

被刻印的时光 ゝ 提交于 2019-12-05 14:24:26

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

hw.gps = yes

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

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

This sample implements GooglePlayServicesClient.ConnectionCallbacks, GooglePlayServicesClient.OnConnectionFailedListener and LocationListener. And also checks for Google Play Services before connecting with the LocationClient (that's why we needed a Google Emulator image.) (See 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.

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

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

 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.

You really should use GENYMOTION it 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 here inside that page look for "GPS widget". Good luck.

Heres a shot from that window

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.

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.

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 genyshell that comes with genymotion

    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 gyebro and 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.

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.

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

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.

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

Make sure your AVD has GPS support hardware set to true

Create New AVD > Hardware > New > GPS support

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.

(or)

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

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.

You should be greeted with an Android console message.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!