3

I am new into Android world. I was just referring this tutorial from Google: http://developer.android.com/training/location/retrieve-current.html

Program compiles fine and launches application on emulator, but when I try to find mLocationClient.getLastLocation() it returns null, ALWAYS

I searched for almost a day and ahve already tried sending parameter from DDMS, telnet, switching google MAPs but still no success.

Please help me out.

Pratik
  • 952
  • 2
  • 16
  • 31

3 Answers3

12

What eventually worked for me was setting a location (I use Genymotion, so the "GPS widget" in the upper right corner), then starting Google Maps, and then running my app.

My guess is that my app wasn't actually setting the current location (which I thought connecting my locationClient would do automatically) - Google Maps checks and sets the location, so getLastLocation actually has something to return.

Jade McGough
  • 348
  • 2
  • 13
  • 1
    Thanks, I also met this problem. The key is you have to enable Location Access setting and run the google map at least once. If you disable the Location Access and re-enable, you have run the google map again else you'll get null Location again. And don't forget to put `` in AndroidManifest.xml – null Aug 31 '14 at 08:56
0

I think the emulator sometimes has its own bugs and issues. maybe that's one of them.

try the next things:

  • use the latest version of Android for the emulator. also update the ADT & SDK to the latest versions.
  • use alternative emulators
  • use real devices
  • use fake-gps-apps (location mocking) which make the OS think that your device is in some position
  • make sure that in the OS settings, mocking of gps locations is enabled
android developer
  • 114,585
  • 152
  • 739
  • 1,270
  • Thanks.. Android Developer. It started working when after sending param from DDMS i first open Maps, but yes it takes so much of time. – Pratik Sep 30 '13 at 10:29
0

Open google map once in the emulator then give all geolocalisation permissions to google map, switch back to your app it should work.

Taoufik J
  • 700
  • 1
  • 9
  • 26