locationclient.getlastlocation() always returns null on emulator

牧云@^-^@ 提交于 2019-12-10 21:56:19

问题


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.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/19090573/locationclient-getlastlocation-always-returns-null-on-emulator

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