我已經嘗試了GPS和網絡提供商,但他們給getLastKnownLocation空位置。我也沒有得到onLocationChanged。我正在從我的公寓裏嘗試牢房信號強。我甚至可以很好地瀏覽互聯網,並從市場上下載和安裝應用程序。android getLaskKnownLocation null
我已閱讀同一主題的幾個線程,但他們的建議似乎我已經嘗試過。
這是我的代碼片段。
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
if(null == locationManager) {
Log.d(TAG, "location manager NULL");
}
geocoder = new Geocoder(this);
// Initialize with the last known location
Location lastLocation = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (lastLocation != null)
onLocationChanged(lastLocation);
else
Log.i(TAG, "null LastKnownLocation");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// TODO Auto-generated method stub
super.onStartCommand(intent, flags, startId);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
0,0, this);
Log.d(TAG, "requested location updates");
return START_STICKY;
}
按日誌:
[email protected]:/media/sf_E_DRIVE/tmp$ adb logcat LocationNotifierService:* *:S
--------- beginning of /dev/log/system
--------- beginning of /dev/log/main
I/LocationNotifierService(30866): null LastKnownLocation
D/LocationNotifierService(30866): gps provider enabled:true
D/LocationNotifierService(30866): network provider enabled:true
D/LocationNotifierService(30866): onCreate
D/LocationNotifierService(30866): requested location updates
D/LocationNotifierService(30866): requested location updates
D/LocationNotifierService(30866): requested location updates
我有「開鎖接收器」所以,當我解開我的屏幕我要求這正從原木預期的位置更新。但onLocationChanged方法沒有被調用。
我已添加權限以顯示罰款和粗略。
Regards,
Miten。
您是否在設備上啓用了位置服務,您是否在清單中添加了權限,如果發送日誌跟蹤,是否會收到任何錯誤?網上有很多教程可以幫助你入門。 – Orlymee