我目前使用計時器來確定位置監聽器是否超時?問題在於GPS仍然在運行。我不知道爲什麼,當locationlistener超時或更優雅的方法時,是否有一種方法可以重寫?LocationListener timeout
回答
考慮將GPS狀態監聽器添加到您的位置管理器。當GPS啓動,停止,接收第一個定位或衛星狀態(可見衛星數量,至少需要4個修正)時,通知狀態監聽器。
監聽器可以是這樣的:
class GpsStatusListener implements GpsStatus.Listener {
@Override
public void onGpsStatusChanged(final int event) {
switch(event) {
// ...
break;
case GpsStatus.GPS_EVENT_STOPPED:
// ...
break;
case GpsStatus.GPS_EVENT_FIRST_FIX:
// ...
break;
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
// ...
break;
}
}
}
據如下補充:
lm.addGpsStatusListener(new GpsStatusListener());
你並不需要刪除位置監聽器GPS狀態發生變化時。
您也可以通過重寫下列方法之一得到位置管理附加信息:
public void onStatusChanged(final String provider, final int status, final Bundle extras) {
switch(status) {
case LocationProvider.AVAILABLE:
// ...
break;
case LocationProvider.OUT_OF_SERVICE:
// ...
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
// ...
break;
}
}
@Override
public void onProviderEnabled(final String provider) {
// ...
}
@Override
public void onProviderDisabled(final String provider) {
// ...
}
當我得到這種情況:案件LocationProvider.AVAILABLE,案件LocationProvider.OUT_OF_SERVICE,案件LocationProvider.TEMPORARILY_UNAVAILABLE,因爲我相信,可能會幫助我與我的問題:http://stackoverflow.com/questions/15747543/locationlistener-of- network-provider-is-enabled-but-onlocationchanged-is-never – 2013-05-24 14:33:45
I記錄每個案例,並在LocationListener(NETWORK_PROVIDER)的onStatusChanged中生成每個案例的報告,但它沒有發生 – 2013-05-24 14:45:05
這取決於您的硬件。如果GPS不能再看到衛星(例如進入建築物時),我有時會得到暫時不可用的信號。我從來沒有看到過服務信號。 – Stefan 2013-05-28 08:20:54
當超時發生或您已獲得當前位置時,您應該刪除位置偵聽器。
- 1. d3 timeout like angular .timeout
- 2. HAProxy,「timeout tunnel」vs「timeout client/server」
- 3. 需要註冊LocationListener?
- 4. Android MyLocationOverlay和LocationManager/LocationListener
- 5. 如何實現LocationListener?
- 6. rqworker timeout
- 7. file_get_contents timeout
- 8. DirectoryEntry Timeout
- 9. HttpWebRequest.GetRequestStream()Timeout
- 10. HttpClientParams timeout
- 11. WebClient TimeOut
- 12. Python Timeout
- 13. 'rbuf_fill'中的救援:Timeout :: Error(Timeout :: Error)
- 14. 如何在沒有「implements LocationListener」的情況下使用LocationListener?
- 15. MobileServiceClient invokeApi timeout
- 16. Selenium C#,WebDriverWait timeout
- 17. Android https timeout
- 18. raw_input和timeout
- 19. jquery autosuggestion和timeout
- 20. PayPal TimeOut - DoExpressCheckoutPayment
- 21. Selenium Firefox Open timeout
- 22. recv(MSG_PEEK)timeout
- 23. InetAddress.getByName(ip).isReachable(timeout);
- 24. hadoop map task timeout
- 25. GWT ie8 timeout 12002
- 26. Kony Publishing Service timeout
- 27. Timeout-Dialog.js問題
- 28. Couchbase BlockForSingle Timeout
- 29. Consuming rest api timeout
- 30. Java InetAddress.isReachable()timeout
什麼是「位置監聽器超時」?當他們沒有在合理的時間內被打電話? – zapl 2012-03-19 10:05:27
是的......當它無法確定一個實際的位置 – opc0de 2012-03-19 10:06:33
你的問題不是很清楚。講清楚 。 – 2012-03-19 10:31:26