Google Play Services LocationClient returns null



我是android新手,我想获得当前位置,我指的是链接http://developer.android.com/training/location/retrieve-current.html,其中显示了使用Google Play服务。

首先,我已经从上面的链接下载了样例LocationUpdates,我正在使用模拟器(AVD与目标Google API Inc,API Level 17,Platform 4.2.2)。

我试图获得当前位置,它返回null。它使用LocationCLient并调用mLocationClient.getLastLocation()。

检查谷歌播放服务是否可用使用GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);这里它返回0(success)。

我已经在模拟器中启用了位置访问:Wifi和GPS卫星。

请帮助我知道缺少什么,以便我得到当前位置。

谢谢

尝试在模拟器上打开谷歌地图一次,以便Google Play服务可以更新,然后从Google设置应用程序的"Google Location"下启用"Access Location"

在这样做之后,我能够使用模拟器控件手动推送gps位置到设备,并从LocationClient访问它们。

如果你的WiFi和GPS服务都是开启的,你的设备实际上也连接了WiFi吗?否则,你的WiFi服务将无法工作,位置提供商将返回到GPS。GPS将无法快速获取您的位置,这导致值(getLastLocation())有时为空。

最新更新