为什么我的位置变量的值为空?我正在正确设置我的 LocationManager。
这是我的源代码:
//Get the current location
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
myCriteria = new Criteria();
String provider = locationManager.getBestProvider(myCriteria, true);
Location location = locationManager.getLastKnownLocation(provider);
boolean isGpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
//Location location;
if (isGpsEnabled) {
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
else {
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
}
Log.i(TAG, "Provider is: "+provider);
Log.i(TAG, "Location is: "+location);
这是 logcat 输出:
06-17 10:40:52.637: D/dalvikvm(15106): GC_FOR_ALLOC freed 534K, 7% free 10586K/11360K, paused 16ms, total 16ms
06-17 10:40:52.677: I/OGT.RideTracking(15106): Provider is: gps
06-17 10:40:52.677: I/OGT.RideTracking(15106): Location is: null
06-17 10:40:52.677: D/AndroidRuntime(15106): Shutting down VM
我的代码有什么问题?