【发布时间】:2014-06-21 09:58:15
【问题描述】:
我正在使用LocationClient 从网络获取用户位置(无 GPS)。
我在创建片段时实例化了LocationClient
mLocationClient = new LocationClient(getActivity(), this, this);
mLocationClient.connect();
后来
if (mLocationClient.isConnected())
{
currentLocation = mLocationClient.getLastLocation();
}
我确定它已连接,但 getLastLocation() 总是返回 null。
但是,它可以使用 LocationManager。
LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
currentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
我知道我可以只使用监听器来更新位置,但我想了解为什么 getLastLocation() 总是返回 null。
【问题讨论】:
-
你是在真机还是模拟器中尝试?
-
@Kedarnath 真机,Galaxy S3
-
@HemantChandDungriyal 我看到了,但很奇怪,因为我在 LocationClient 或多或少初始化 5 秒后调用该函数
-
打开谷歌地图初始化并访问某个位置,然后尝试你的应用程序。
-
我做到了,但没有任何改变:(
标签: android geolocation