android - 即使沒有可用的互聯網,也會調用 onLocationChanged (android - onLocationChanged is called even when there is not internet available)


問題描述

android ‑ 即使沒有可用的互聯網,也會調用 onLocationChanged (android ‑ onLocationChanged is called even when there is not internet available)

我只是想知道這個,因為它沒有意義。

我連接了一個 GoogleApiClient,之後我使用

請求位置更新p>
LocationServices.FusedLocationApi.requestLocationUpdates(
googleApiClient, mLocationRequest, this);

現在,奇怪的是 ‑ 即使我將手機置於飛行模式,onLocationChanged(Location location) 也會被調用!沒有互聯網,我仍然可以獲得位置更新。這怎麼可能?這些更新是否可靠且準確?


參考解法

方法 1:

In regular situations, the location is calculated based on one or several sensors. The data include:

  • Cellular networks.
  • Surrounding Wi‑Fi networks.
  • Surrounding bluetooth beacons.
  • GPS.

The first 3 methods require radios that can both listen and broadcast radio signals, however the GPS only listens for signals broadcasted by satellites, as it does not broadcasts anything. When you activate the airplane mode, you are basically telling to the device to stop broadcasting any kind of signal (in order to avoid interferences with the aircraft), however as the GPS chip does not broadcast anything, it can be expected to keep listening for satelite signals and thus, reporting you back the device current location.

You can programatically detect the accuracy of the location object by calling:

location.getAccuracy();

Which is the accuracy of the location in meters.

Edit: Let me add some important points that might be interesting for you:

  • GPS first fix is really slow if it does not have assistance from any other radio. It can take minutes until you see the first location.
  • GPS needs a clear view of the sky in order to receive signals. So it won't work indoors.
  • GPS is one of the more power consuming ways to get location, compared with other techniques.

方法 2:

In a case where there are no internet or any update yet, it returns your last know location. so even in flight mode, you will probably still get it, it will only change once there is a new location update which will or may require internet before getting

(by Ofek AgmontomaccoMuyide Ibukun)

參考文件

  1. android ‑ onLocationChanged is called even when there is not internet available (CC BY‑SA 2.5/3.0/4.0)

#android-googleapiclient #google-maps-android-api-2 #Android #updates #android-location






相關問題

Scope 在 GoogleApiClient 中的作用是什麼? (What does Scope do in GoogleApiClient?)

Android studio - 將 GCM api 更新為 Google 服務 (Android studio - updating GCM api to Google services)

Android:為沒有 Google Play 服務的用戶登錄 Google? (Android: Google signin for a user without Google Play Services?)

GoogleApiClient onConnected 未被調用,在服務中使用 (GoogleApiClient onConnected not being called, using in a Service)

從 Play 商店安裝應用程序後嘗試使用 Google 登錄時出現“使用 Google 進行身份驗證時出錯:未知”異常。閱讀詳情 (Getting 'Error authenticating with Google: unknown' exception when trying to signin with google after installing app from play store. See details)

Android google Sign In 總是顯示 handleSignInResult:false (Android google Sign In always shows handleSignInResult:false)

Android Google Play 遊戲服務 (Android Google Play Games Services)

android - 即使沒有可用的互聯網,也會調用 onLocationChanged (android - onLocationChanged is called even when there is not internet available)







留言討論