Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to know my location came from gps or glonass?

Suppose the device support both gps and glonass(support at the hardware level).

Now when I get location by the android.location API, is it possible to know the hardware where the location came from?


LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener());

class LocationListener implement LocationListener(){
    @Override
    public void onLocationChanged(Location location) {
        GPSStatus status=locationManager.getGpsStatus();
        //check the PRN of the satellites from the status
        //but how can be granted that the `status` object obtained here is exactly the same when it was used to calculate the location?
    }
}

If we use the GPSStatus.Listener like this:

class LocationListener implement LocationListener,GPSStatus.Listener(){
    private GPSStatus status;
    @Override
    public void onLocationChanged(Location location) {
        if(status!=null){
            //status should be the GPSStatus before get this location
            //check the PRN of the satellites from the status
            //How it can be granted that the `onGpsStatusChanged` will be called before the `onLocationChanged` by the Android System?
        }

    }
   public void onGpsStatusChanged(int event) {
        status = locationManager.getGpsStatus(null);    
    }
}
like image 334
hguser Avatar asked Mar 18 '23 12:03

hguser


1 Answers

The hardware the location came from is the GPS/GLONASS chip in your phone. The chip receives signals from satellites orbiting the earth.

GPS and GLONASS satellites are used in combination on devices that support this. To determine if GLONASS satellites were used to determine the location, you can either register a GpsStatusListener or call LocationManager.getGpsStatus(). Call getSatellites() on the GpsStatus object and call getPrn() on each GpsSatellite object in the returned list. If the value is between 65 and 88 and the usedInFix() method returns true the last position was calculated using a GLONASS satellite.

See http://developer.sonymobile.com/knowledge-base/technologies/glonass/

like image 56
David Wasser Avatar answered Apr 25 '23 20:04

David Wasser