Getting the number of satellites from Location object

匆匆过客 提交于 2019-11-28 20:41:27

问题


I'm using a GPS provider and LocationListener.onLocationChanged(Location location) to receive location fixes.
Documentation says, that Location.getExtras() contains next key/value pair:

satellites - the number of satellites used to derive the fix

but on practice I'm getting an empty extra object - there is no any data there.
Does it means that I'm getting the A-GPS fixes and not GPS?


回答1:


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+")"); 
}



回答2:


I use Location.getExtras().getInt("satellites"), and it give the number of satellites in use.




回答3:


Nope it means that your phone manufacturer decided not to implement this. (Or you could be using the NETWORK_PROVIDER which does not use satellites)

Use a NmeaListener and parse the sentences to know the number of satellites visible or used.



来源:https://stackoverflow.com/questions/6580603/getting-the-number-of-satellites-from-location-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!