4

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 Controls and then I hit "Send".

enter image description here

But it doesn't work. Instead I see the following error: 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

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

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

telnet localhost 5554
geo fix 50 50

It responds with OK but nothing happens. Still no location data available.

Update3: I notice a stream of the following errors in 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

No mention of "GPS Support".

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.

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

Here's what I see in the LogCat:

6
  • Does yourLocationClient.getLastLocation() return with null? Are you implementing LocationListener? Could anything interfere with your emulator port (5554)? Have you tried Android Studio (and its Android Device Monitor)?
    – Gyebro
    Commented Sep 23, 2014 at 10:54
  • There is no location listener. As for yourLocatoinClient, I'm very new to Android development so I'm not sure what that is. If you give me instructions I'll test. I haven't tried Android Studio but I tried with Genymotion plugin and it STILL didn't work. Commented Sep 23, 2014 at 14:13
  • Just check if your AVD has these settings: AVD -> Hardware -> New -> GPS support -> "Yes" Commented Sep 24, 2014 at 6:41
  • @SagarPilkhwal I'm not seeing that option. From Eclipse I open the "Android Virtual Device Manager" and it shows a list of AVDs but "GPS Support" field. Commented Sep 24, 2014 at 15:14
  • *no "GPS Support" field Commented Sep 24, 2014 at 15:34

5 Answers 5

6
+200

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.

10
  • Thanks. I checked the config.ini file for all my AVDs and they are all correctly set to hw.gps=yes. See my Update 5 above. I'm slow working with Eclipse, so I haven't tried the Location Test yet... but I'm not sure what it's testing for. I know GPS is unavailable because I can use the default internet browser to visit a page which requests geolocation data and it doesn't work. Should I still proceed with the Location Test? Commented Sep 24, 2014 at 17:49
  • @SDP I definitely suggest to try that little demo app (only a single activity, plus some permissions in the AndroidManifest). I've tried html5demos.com/geo with the Emulator's browser and it does not work. (Maybe it reads the last location. No location icon appears in the status bar)
    – Gyebro
    Commented Sep 24, 2014 at 18:05
  • @SDP After I've requested location update with the test app, html5demos.com/geo manages to get the location. (However it does not request location update itself.)
    – Gyebro
    Commented Sep 24, 2014 at 18:13
  • 1
    That's interesting! In my quest to figure this out I've heard other stories about geolocations not working until something else triggered them. I'll try the app asap. Commented Sep 24, 2014 at 19:44
  • @SDP I hope you will succeed!
    – Gyebro
    Commented Sep 24, 2014 at 20:21
2

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

genymotino gps widget

1

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. location test demo

1

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.

3
  • I did try with the free version of Genymotion, but it also didn't work even after I set the GPS location using the button. I appreciate the suggestion, but it's not actually an answer to the question I asked so it probably belongs in a discussion elsewhere. Commented Sep 24, 2014 at 19:47
  • Well, genymotion is an awesome emulator. it is a shame it didn't work
    – Ercan
    Commented Sep 29, 2014 at 15:34
  • Genymotion is not longer free! Commented Dec 4, 2016 at 12:08
0

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.