Getting the number of satellites from Location object

前端 未结 3 677
天命终不由人
天命终不由人 2020-12-24 09:46

I\'m using a GPS provider and LocationListener.onLocationChanged(Location location) to receive location fixes.
Documentation says, that Location.getExtras() contains nex

3条回答
  •  渐次进展
    2020-12-24 10:42

    To get the number of satellites used by the GPS engine you need to implement android.location.GpsStatus.Listener and implement its method onGpsStatusChanged().

    Example...

    public void onGpsStatusChanged(int event) {
        int satellites = 0;
        int satellitesInFix = 0;
        int timetofix = locationManager.getGpsStatus(null).getTimeToFirstFix();
        Log.i(TAG, "Time to first fix = " + timetofix);
        for (GpsSatellite sat : locationManager.getGpsStatus(null).getSatellites()) {
            if(sat.usedInFix()) {
                satellitesInFix++;              
            }
            satellites++;
        }
        Log.i(TAG, satellites + " Used In Last Fix ("+satellitesInFix+")"); 
    }
    

提交回复
热议问题