![](/img/trans.png)
[英]locationManager.getLastKnownLocation returns null after request
[英]getLastKnownLocation() returns null ; it was working a day ago
getLastKnownLocation現在返回null,但一天前完全正常工作! 現在,來自不同手機的聲音始終為零。
可能是什么問題呢 ? 我是否以錯誤的方式實施它? locationFetch線程不斷運行-內部實現了while循環-並負責在每次更改時調用“ onLocationChanged”函數。
Runnable locationFetchRun = new Runnable()
{
public void run()
{
tracker = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
Location location;
boolean enabled;
// Initialize the location fields
while( !isFinishing() )
{
Log.i("Homepage","User id value "+user_id);
tracker = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
enabled = tracker
.isProviderEnabled(LocationManager.GPS_PROVIDER);
connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
//Brick point
if(!enabled || activeNetworkInfo.isConnected()!= true)
{
continue;
}
provider = tracker.getBestProvider(criteria, true);
location = tracker.getLastKnownLocation(provider);
if (location != null)
{
gps_state = 1;
onLocationChanged(location);
}
else
gps_state = 0;
}
}
};
//Start location fetch thread
Thread locationFetch = new Thread(locationFetchRun);
locationFetch.start();
它實際上並沒有停止工作,只是花費了很多時間來獲取坐標。.我將尋找另一種解決方案,以節省時間和電話電池; 從更改整個功能開始,到在循環結束時設置適當的超時。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.