use of android.location.GpsSatellite in project DataLogger by sussexwearlab.
the class SatelliteDataCollector method logSatelliteInfo.
private void logSatelliteInfo(Iterable<GpsSatellite> gpsSatellites) {
int satCounter = 0;
// System nanoseconds since boot, including time spent in sleep.
long nanoTime = SystemClock.elapsedRealtimeNanos() + mNanosOffset;
// System local time in millis
long currentMillis = (new Date()).getTime();
String message = String.format("%s", currentMillis) + ";" + String.format("%s", nanoTime) + ";" + String.format("%s", mNanosOffset);
for (GpsSatellite satellite : gpsSatellites) {
satCounter++;
// PRN (pseudo-random number) for the satellite.
int prn = satellite.getPrn();
// Signal to noise ratio for the satellite.
float snr = satellite.getSnr();
// Azimuth of the satellite in degrees.
float azimuth = satellite.getAzimuth();
// Elevation of the satellite in degrees.
float elevation = satellite.getElevation();
message += ";" + prn + ";" + snr + ";" + azimuth + ";" + elevation;
}
message += ";" + Integer.toString(satCounter);
logger.log(message);
logger.log(System.lineSeparator());
}
use of android.location.GpsSatellite in project satstat by mvglasow.
the class PasvLocListenerService method onLocationChanged.
@Override
public void onLocationChanged(Location location) {
if (!location.getProvider().equals(LocationManager.GPS_PROVIDER))
return;
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 = "";
if (prefCoord == Const.KEY_PREF_COORD_DECIMAL) {
title = String.format("%.5f%s%s %.5f%s%s", lat, getString(R.string.unit_degree), ns, lon, getString(R.string.unit_degree), ew);
} else if (prefCoord == Const.KEY_PREF_COORD_MIN) {
double decY = lat;
double degY = (int) decY;
double minY = Math.abs(60.0 * (decY - degY));
double decX = lon;
double degX = (int) decX;
double minX = Math.abs(60.0 * (decX - degX));
title = String.format("%.0f%s %.3f' %s %.0f%s %.3f' %s", degY, getString(R.string.unit_degree), minY + /*rounding*/
0.0005, ns, degX, getString(R.string.unit_degree), minX + /*rounding*/
0.0005, ew);
} else if (prefCoord == Const.KEY_PREF_COORD_SEC) {
double decY = lat;
double degY = (int) decY;
double tmp = 60.0 * (decY - degY);
double minY = (int) Math.abs(tmp);
double secY = Math.abs(60.0 * (tmp - minY));
double decX = lon;
double degX = (int) decX;
tmp = 60.0 * (decX - degX);
double minX = (int) Math.abs(tmp);
double secX = Math.abs(60.0 * (tmp - minX));
title = String.format("%.0f%s %.0f' %.1f\" %s %.0f%s %.0f' %.1f\" %s", degY, getString(R.string.unit_degree), minY, secY + /*rounding*/
0.05, ns, degX, getString(R.string.unit_degree), minX, secX + /*rounding*/
0.05, ew);
} else if (prefCoord == Const.KEY_PREF_COORD_MGRS) {
title = new LatLng(location.getLatitude(), location.getLongitude()).toMGRSRef().toString(MGRSRef.PRECISION_1M);
} else if (prefCoord == Const.KEY_PREF_COORD_UTM) {
title = UTM.lat_lon_to_utm(location.getLatitude(), location.getLongitude(), this.getApplicationContext());
}
String text = "";
if (location.hasAltitude()) {
text = text + String.format("%.0f%s", (location.getAltitude() * (prefUnitType ? 1 : 3.28084)), getString(((prefUnitType) ? R.string.unit_meter : R.string.unit_feet)));
}
if (location.hasSpeed()) {
text = text + (text.equals("") ? "" : ", ") + String.format("%.0f%s", (location.getSpeed() * (prefKnots ? 1.943844 : prefUnitType ? 3.6 : 2.23694)), getString(((prefKnots) ? R.string.unit_kn : (prefUnitType) ? R.string.unit_km_h : R.string.unit_mph)));
}
if (location.hasAccuracy()) {
text = text + (text.equals("") ? "" : ", ") + String.format("\u03b5 = %.0f%s", (location.getAccuracy() * (prefUnitType ? 1 : 3.28084)), getString(((prefUnitType) ? R.string.unit_meter : R.string.unit_feet)));
}
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);
}
}
use of android.location.GpsSatellite in project satstat by mvglasow.
the class MainActivity method onGpsStatusChanged.
/**
* Called when the status of the GPS changes. Updates GPS display.
*/
public void onGpsStatusChanged(int event) {
GpsStatus status = locationManager.getGpsStatus(null);
int satsInView = 0;
int satsUsed = 0;
Iterable<GpsSatellite> sats = status.getSatellites();
for (GpsSatellite sat : sats) {
satsInView++;
if (sat.usedInFix()) {
satsUsed++;
}
}
if (gpsSectionFragment != null) {
gpsSectionFragment.onGpsStatusChanged(status, satsInView, satsUsed, sats);
}
if (mapSectionFragment != null) {
mapSectionFragment.onGpsStatusChanged(status, satsInView, satsUsed, sats);
}
}
use of android.location.GpsSatellite in project satstat by mvglasow.
the class GpsStatusView method onDraw.
@Override
protected void onDraw(Canvas canvas) {
int cx = mW / 2;
int cy = mH / 2;
// Log.d("GpsStatusView", String.format("Drawing on a %dx%d canvas", w, h));
canvas.translate(cx, cy);
canvas.rotate(-mRotation);
canvas.drawCircle(0, 0, mW * 0.37125f, gridBorderPaint);
canvas.drawLine(-mW * 0.405f, 0, mW * 0.405f, 0, gridPaint);
canvas.drawLine(0, -mH * 0.405f, 0, mH * 0.405f, gridPaint);
canvas.drawCircle(0, 0, mW * 0.405f, gridPaint);
canvas.drawCircle(0, 0, mW * 0.27f, gridPaint);
canvas.drawCircle(0, 0, mW * 0.135f, gridPaint);
canvas.drawPath(northArrow, northPaint);
canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_N), labelPathN, 0, -labelPaint.descent(), labelPaint);
canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_S), labelPathS, 0, -labelPaint.descent(), labelPaint);
canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_E), labelPathE, 0, -labelPaint.descent(), labelPaint);
canvas.drawTextOnPath(((Activity) getContext()).getString(R.string.value_W), labelPathW, 0, -labelPaint.descent(), labelPaint);
if (mSats != null) {
for (GpsSatellite sat : mSats) {
drawSat(canvas, sat.getPrn(), sat.getAzimuth(), sat.getElevation(), sat.getSnr(), sat.usedInFix());
}
}
}
Aggregations