List of usage examples for android.location GpsSatellite usedInFix
public boolean usedInFix()
From source file:com.esri.cordova.geolocation.utils.JSONHelper.java
/** * Converts GpsStatus into JSON.//w w w . j a v a2 s.c o m * @param gpsStatus Send a GpsStatus whenever the GPS fires * @return JSON representation of the satellite data */ public static String satelliteDataJSON(GpsStatus gpsStatus) { final Calendar calendar = Calendar.getInstance(); final JSONObject json = new JSONObject(); try { json.put("provider", SATELLITE_PROVIDER); json.put("timestamp", calendar.getTimeInMillis()); if (gpsStatus.getSatellites() != null) { int count = 0; final int timeToFirstFix = gpsStatus.getTimeToFirstFix(); for (GpsSatellite sat : gpsStatus.getSatellites()) { final JSONObject satelliteInfo = new JSONObject(); satelliteInfo.put("PRN", sat.getPrn()); satelliteInfo.put("timeToFirstFix", timeToFirstFix); satelliteInfo.put("usedInFix", sat.usedInFix()); satelliteInfo.put("azimuth", sat.getAzimuth()); satelliteInfo.put("elevation", sat.getElevation()); satelliteInfo.put("hasEphemeris", sat.hasEphemeris()); satelliteInfo.put("hasAlmanac", sat.hasAlmanac()); satelliteInfo.put("SNR", sat.getSnr()); json.put(Integer.toString(count), satelliteInfo); count++; } } } catch (JSONException exc) { logJSONException(exc); } return json.toString(); }
From source file:uk.ac.horizon.ubihelper.service.channel.GpsStatusChannel.java
public void onGpsStatusChanged(int type) { if (location != null) { GpsStatus status = location.getGpsStatus(null); JSONObject value = new JSONObject(); try {// w ww . jav a2 s . c o m // event time is in nanoseconds value.put("timestamp", System.currentTimeMillis()); value.put("status", type); value.put("maxSatellites", status.getMaxSatellites()); value.put("timeToFirstFix", status.getTimeToFirstFix()); JSONArray sats = new JSONArray(); value.put("satellites", sats); for (GpsSatellite satellite : status.getSatellites()) { JSONObject s = new JSONObject(); s.put("used", satellite.usedInFix()); s.put("azimuth", satellite.getAzimuth()); s.put("elevation", satellite.getElevation()); s.put("prn", satellite.getPrn()); s.put("snr", satellite.getSnr()); sats.put(s); } onNewValue(value); } catch (JSONException e) { /* ignore */ } } }
From source file:org.runnerup.tracker.GpsStatus.java
@Override public void onGpsStatusChanged(int event) { if (locationManager == null) return;/*from w w w . j a va2s .com*/ //noinspection MissingPermission android.location.GpsStatus gpsStatus = locationManager.getGpsStatus(null); if (gpsStatus == null) return; int cnt0 = 0, cnt1 = 0; Iterable<GpsSatellite> list = gpsStatus.getSatellites(); for (GpsSatellite satellite : list) { cnt0++; if (satellite.usedInFix()) { cnt1++; } } mKnownSatellites = cnt0; mUsedInLastFixSatellites = cnt1; if (listener != null) listener.onTick(); }
From source file:com.vonglasow.michael.satstat.PasvLocListenerService.java
@Override public void onGpsStatusChanged(int event) { GpsStatus status = mLocationManager.getGpsStatus(null); int satsUsed = 0; Iterable<GpsSatellite> sats = status.getSatellites(); for (GpsSatellite sat : sats) { if (sat.usedInFix()) { satsUsed++;//from w w w.j av a 2 s . co m } } if (satsUsed == 0) { if (mStatus != GPS_INACTIVE) mStatus = GPS_SEARCH; showStatusNoLocation(); } }
From source file:org.mozilla.mozstumbler.service.stumblerthread.scanners.GPSScanner.java
private void startActiveMode() { LocationManager lm = getLocationManager(); if (!isGpsAvailable(lm)) { return;/* w ww.java2 s . c o m*/ } lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, ACTIVE_MODE_GPS_MIN_UPDATE_TIME_MS, ACTIVE_MODE_GPS_MIN_UPDATE_DISTANCE_M, this); reportLocationLost(); mGPSListener = new GpsStatus.Listener() { public void onGpsStatusChanged(int event) { if (event == GpsStatus.GPS_EVENT_SATELLITE_STATUS) { GpsStatus status = getLocationManager().getGpsStatus(null); Iterable<GpsSatellite> sats = status.getSatellites(); int satellites = 0; int fixes = 0; for (GpsSatellite sat : sats) { satellites++; if (sat.usedInFix()) { fixes++; } } if (fixes < MIN_SAT_USED_IN_FIX) { reportLocationLost(); } } else if (event == GpsStatus.GPS_EVENT_STOPPED) { reportLocationLost(); } } }; lm.addGpsStatusListener(mGPSListener); }
From source file:com.vonglasow.michael.satstat.PasvLocListenerService.java
@Override public void onLocationChanged(Location location) { if (!location.getProvider().equals(LocationManager.GPS_PROVIDER)) return;/*from w w w . j a va2 s . co m*/ if (mNotifyFix && (mStatus != GPS_INACTIVE)) { mStatus = GPS_FIX; GpsStatus status = mLocationManager.getGpsStatus(null); int satsInView = 0; int satsUsed = 0; Iterable<GpsSatellite> sats = status.getSatellites(); for (GpsSatellite sat : sats) { satsInView++; if (sat.usedInFix()) { satsUsed++; } } double lat = Math.abs(location.getLatitude()); double lon = Math.abs(location.getLongitude()); String ns = (location.getLatitude() > 0) ? getString(R.string.value_N) : (location.getLatitude() < 0) ? getString(R.string.value_S) : ""; String ew = (location.getLongitude() > 0) ? getString(R.string.value_E) : (location.getLongitude() < 0) ? getString(R.string.value_W) : ""; String title = String.format("%.5f%s%s %.5f%s%s", lat, getString(R.string.unit_degree), ns, lon, getString(R.string.unit_degree), ew); String text = ""; if (location.hasAltitude()) { text = text + String.format("%.0f%s", location.getAltitude(), getString(R.string.unit_meter)); } if (location.hasSpeed()) { text = text + (text.equals("") ? "" : ", ") + String.format("%.0f%s", (location.getSpeed() * 3.6), getString(R.string.unit_km_h)); } if (location.hasAccuracy()) { text = text + (text.equals("") ? "" : ", ") + String.format("\u03b5 = %.0f%s", location.getAccuracy(), getString(R.string.unit_meter)); } text = text + (text.equals("") ? "" : ", ") + String.format("%d/%d", satsUsed, satsInView); text = text + (text.equals("") ? "" : ",\n") + String.format("TTFF %d s", status.getTimeToFirstFix() / 1000); mBuilder.setSmallIcon(R.drawable.ic_stat_notify_location); mBuilder.setContentTitle(title); mBuilder.setContentText(text); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(text)); startForeground(ONGOING_NOTIFICATION, mBuilder.build()); } else { stopForeground(true); } }
From source file:com.asc.msigeosystems.prism4d.YGPS.java
/**************** @Override/* w w w . j av a 2 s .c om*/ public void onNmeaReceived(long timestamp, String nmea) { //create an object with all the fields from the string mNmeaData = mNmeaParser.parse(nmea); //update the UI //updateNmeaUI(mNmeaData); //save the raw data //get the nmea container Prism4DNmeaContainer nmeaContainer = Prism4DNmeaContainer.getInstance(); nmeaContainer.add(mNmeaData); } *******************************/ //*********************** End of Callbacks *******************// //******************** Callback Utilities *****************// // Called by OS when a Listener condition is met // //************************************************************// //Update the UI with satellite status info from GPS protected void setGpsStatus() { if (mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { //location manager is enabled, //update the UI with info from GPS mGpsStatus = mLocationManager.getGpsStatus(mGpsStatus); //get satellite data from GPS Iterable<GpsSatellite> sats = mGpsStatus.getSatellites(); int inSky = 0; int inFix = 0; for (GpsSatellite s : sats) { inSky += 1; if (s.usedInFix()) { inFix += 1; } } //update the UI with the GPS info mSatInSky.setData(inSky); //indicate whether the position is fixed (locked) or not mSatInFix.setData(inFix); if (inFix > 0) { mGpsState.stateLock(); } else { mGpsState.stateOn(); } mTtff.setData(mGpsStatus.getTimeToFirstFix()); } else { //location manager is not enabled, u // pdate the UI with that mGpsState.stateOff(); mSatInFix.setData("no fix"); mSatInSky.setData("gps off"); } mPositionView.postInvalidate(); mSignalView.postInvalidate(); }
From source file:com.alexandreroman.nrelay.NmeaRelayService.java
@Override public void onGpsStatusChanged(int event) { if (GpsStatus.GPS_EVENT_STARTED == event) { Log.i(TAG, "GPS started"); } else if (GpsStatus.GPS_EVENT_STOPPED == event) { Log.i(TAG, "GPS stopped"); } else if (GpsStatus.GPS_EVENT_FIRST_FIX == event) { Log.i(TAG, "GPS first fix"); } else if (GpsStatus.GPS_EVENT_SATELLITE_STATUS == event) { if (locationManager != null) { final GpsStatus s = locationManager.getGpsStatus(null); context.satellitesInUse = 0; context.satellitesInView = 0; for (final GpsSatellite sat : s.getSatellites()) { if (sat.usedInFix()) { context.satellitesInUse += 1; }// w ww . j a va 2 s . com context.satellitesInView += 1; } if (BuildConfig.DEBUG) { Log.v(TAG, "GPS satellite status: " + context.satellitesInUse + " satellite(s) used in fix"); } fireNmeaRelayContextChanged(); } } }
From source file:com.nextgis.maplibui.service.TrackerService.java
@Override public void onGpsStatusChanged(int event) { switch (event) { case GpsStatus.GPS_EVENT_STARTED: case GpsStatus.GPS_EVENT_STOPPED: mHasGPSFix = false;//from w w w . j av a 2s .c o m break; case GpsStatus.GPS_EVENT_FIRST_FIX: mHasGPSFix = true; break; case GpsStatus.GPS_EVENT_SATELLITE_STATUS: mSatellitesCount = 0; for (GpsSatellite sat : mLocationManager.getGpsStatus(null).getSatellites()) { if (sat.usedInFix()) { mSatellitesCount++; } } break; } }
From source file:com.tritop.androsense2.fragments.GpsFragment.java
@Override public void onGpsStatusChanged(int arg0) { long triggerTime = System.currentTimeMillis(); int gpsSatellitesCount = 0; int glonassSatellitesCount = 0; HashMap<String, String> mSatInfo; itemListGps.clear();// w ww.j a v a 2s. c om itemListGlonass.clear(); GpsStatus gpsStatus = mLocationManager.getGpsStatus(null); Iterable<GpsSatellite> gpsSats = gpsStatus.getSatellites(); for (GpsSatellite sat : gpsSats) { if (sat.getPrn() <= 32) { gpsSatellitesCount++; mSatInfo = new HashMap<String, String>(); mSatInfo.put(SAT_PNR_KEY, String.valueOf(sat.getPrn())); String usedinfix = (sat.usedInFix()) ? "TRUE" : "FALSE"; mSatInfo.put(SAT_FIX_KEY, usedinfix); itemListGps.add(mSatInfo); } else { glonassSatellitesCount++; mSatInfo = new HashMap<String, String>(); mSatInfo.put(SAT_PNR_KEY, String.valueOf(sat.getPrn())); String usedinfix = (sat.usedInFix()) ? "TRUE" : "FALSE"; mSatInfo.put(SAT_FIX_KEY, usedinfix); itemListGlonass.add(mSatInfo); } } if (isLogging && mGpsLog != null) { try { mGpsLog.logEvent(triggerTime, gpsSatellitesCount + glonassSatellitesCount, gpsSats, mLatitude, mLongitude, mAltitude, mAccuracy); } catch (IOException e) { e.printStackTrace(); } } satView.setSatellites(gpsSats); mGpsListAdapter.notifyDataSetChanged(); mGlonassListAdapter.notifyDataSetChanged(); satView.invalidate(); }