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 hardw
Typically, most devices that support both Glonass and GPS will combine measurements from the two constellations to make a position. You don't get one or the other, you normally get both. The mix of GPS vs Glonass constellations will depend on where you are and what satellites are visible.
As Batuhan shows above, the way to tell which satellites are used is to walk the list of satellites reported, find the satellites used in the fix, and then look at their ID numbers. ID values of 1 to 32 are for GPS satellites, 65 to 88 are Glonass. The one thing to remember is that standard android has a brain-dead header file called gps.h that doesn't understand about other constellations like Glonass, it only likes GPS. There is a simple tweak that many manufacturers do when parsing pulling data from the GPS driver to fix this, but it needs to be done on both the App processor side and inside the GPS driver code. You can't just tweak this stuff on one side without matching changes on the other. Hopefully, your device is one that has this change so you can see satellite ID numbers from all constellations.
As @DavidWasser said, it is possible to know that. I wanted to share some codes in addition to @DavidWasser 's answer.
You should have LocationManager object:
private LocationManager locationManager;
and you initialize that with:
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Request location updates with your implements LocationListener, GpsStatus.Listener
class:
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
new GPSLocationListener());
GPSLocationListenerClass:
private class GPSLocationListener implements LocationListener,
GpsStatus.Listener {
private boolean isGPSFix;
public void onGpsStatusChanged(int event) {
checkGlonassFeature(); // the method which checks if locations from GLONASS or GPS
switch (event) {
case GpsStatus.GPS_EVENT_SATELLITE_STATUS:
if (mLastLocation != null)
isGPSFix = (SystemClock.elapsedRealtime() - lastGPStime) < 3000;
if (isGPSFix) { // A fix has been acquired.
Toast toast = Toast.makeText(GPSLocationService.this, "GPS has a fix.", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
} else { // The fix has been lost.
Toast toast = Toast.makeText(GPSLocationService.this, "GPS DOES NOT have a fix.", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
break;
case GpsStatus.GPS_EVENT_FIRST_FIX:
Toast toast = Toast.makeText(GPSLocationService.this, "GPS got first fix.", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
isGPSFix = true;
break;
}
}
@Override
public void onLocationChanged(Location location) {
// Do works here
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
String statusDescription = "unknown";
switch (status) {
case LocationProvider.OUT_OF_SERVICE:
statusDescription = "OUT_OF_SERVICE";
break;
case LocationProvider.AVAILABLE:
statusDescription = "AVAILABLE";
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
statusDescription = "TEMPORARILY_UNAVAILABLE";
break;
}
}
@Override
public void onProviderEnabled(String provider) {
Toast toast = Toast.makeText(GPSLocationService.this, "GPS feature is active", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
@Override
public void onProviderDisabled(String provider) {
Toast toast = Toast.makeText(GPSLocationService.this, "GPS feature is passive", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
and Finally your control method:
public void checkGlonassFeature() {
boolean isGPSFromGlonass = false;
final GpsStatus gs = this.locationManager.getGpsStatus(null);
final Iterable<GpsSatellite> it = gs.getSatellites();
for (GpsSatellite sat : it) {
if(sat.usedInFix()){
if(sat.getPrn() > 65 && sat.getPrn() < 88)
isGPSFromGlonass = true;
else
isGPSFromGlonass = false;
}
else
isGPSFromGlonass = false;
}
if(isGPSFromGlonass){
Toast toast = Toast.makeText(getBaseContext(), "Location from GLONASS", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
else{
Toast toast = Toast.makeText(getBaseContext(), "Location from GPS", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
}
}
Note that it is only addition to above answer. Good luck.
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/