【发布时间】:2012-08-19 16:31:49
【问题描述】:
我是安卓新手。我正在尝试使用 GPS 获取我的位置。 我已包含权限:
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
每当我尝试使用getLastKnownLocation 从LocationManager 获取我的Location 时,我都会得到空对象。此外,GPS 已启用。这是我的代码:
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
Location location;
if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Log.d("ManualLog", "GPS_DISABLED");
Intent settingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(settingsIntent);
} else {
Log.d("ManualLog", "GPS_ENABLED");
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
}
【问题讨论】: