我正在使用GPS。这是我的代码。getLastKnownLocation返回NULL
public void onCreate()
{
super.onCreate();
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location mLocation;
if(mLocationManager.isProviderEnabled((LocationManager.GPS_PROVIDER)))
{
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER , 2000, 10, myLocationListener);
mLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Temp = updateWithNewLocation(mLocation);
Value.city = Temp;
Temp = "";
LogShow("DataClass.City = " + Value.city);
LogShow("GPS_PROVIDER enable");
}
}
我不知道为什么getLastKnownLocation返回NULL。所以updateWithNewLocation将是空的。 我使用权限ACCESS FINE LOCATION。
我该如何解决?
'getLastKnownLocation()'如果认为位置过于过时将返回空值 – 2013-03-19 07:54:44
@raghav表示的过期getLastKnownLocation(),例如,如果设备已关闭并移动到另一个位置。应该通过请求新的位置更新来获取新位置。另外,我会建议考虑您的准确度和电池限制,以便继续使用NETWORK_PROVIDER而不是GPS_PROVIDER – 2013-03-19 08:00:49