問題是自我解釋。在調試時,我看到該位置爲空。請建議進一步分類。gps.getLasknowlocation甚至在設置位置之後在模擬器中返回null?
locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
....
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
// locationManager.requestLocationUpdates(
// LocationManager.GPS_PROVIDER,
// MIN_TIME_BW_UPDATES,
// MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
在調試我看到gpsEnabled是alwaysreturned假的。 GPS在模擬器上打開
更新了我的問題 –
問題在於您正在使用模擬器。更新我的回答 –
我試圖用你認爲的方式,即使是地圖等待的位置。 –