public LocationAssert hasNoSpeed() { isNotNull(); assertThat(actual.hasSpeed()) // .overridingErrorMessage("Expected to not have speed but did.") // .isFalse(); return this; }
public LocationAssert hasSpeed() { isNotNull(); assertThat(actual.hasSpeed()) // .overridingErrorMessage("Expected to have speed but did not.") // .isTrue(); return this; }
coordinates.put(PARAM_HEADING, location.getBearing()); if (location.hasSpeed()) { coordinates.put(PARAM_SPEED, location.getSpeed());
/** * Formats the speed in knots from the #Location into a string. * If the speed is unknown, it returns an empty string. */ public static String formatSpeedKt(Location location) { String s = ""; if (location.hasSpeed()) // http://www.google.com/search?q=m%2Fs+to+kt s += (location.getSpeed() * 1.94384449); return s; }
public float getSpeed() { return _Location.hasSpeed() ? _Location.getSpeed() : NOT_AVAILABLE; } public float getAccuracy() { return _Location.hasAccuracy() ? _Location.getAccuracy() : NOT_AVAILABLE; }
public LocationAssert hasNoSpeed() { isNotNull(); assertThat(actual.hasSpeed()) // .overridingErrorMessage("Expected to not have speed but did.") // .isFalse(); return this; }
public LocationAssert hasSpeed() { isNotNull(); assertThat(actual.hasSpeed()) // .overridingErrorMessage("Expected to have speed but did not.") // .isTrue(); return this; }
/** * Calculates the speed from current location object. * If location has speed, this one will be used else the speed will be calculated from current * and last position. */ private void calculateSpeed(Location location){ double newTime= System.currentTimeMillis(); double newLat = location.getLatitude(); double newLon = location.getLongitude(); if(location.hasSpeed()){ Log.i(LOG_TAG, "Location has speed"); speed = location.getSpeed(); } else { Log.i(LOG_TAG, "Location has no speed"); double distance = calculationBydistance(newLat,newLon,oldLat,oldLon); double timeDifferent = (newTime - curTime) / 1000; // seconds speed = (float) (distance / timeDifferent); curTime = newTime; oldLat = newLat; oldLon = newLon; } Intent localIntent = new Intent(BROADCAST_ACTION_SPEED_CHANGED) // Add new step count .putExtra(EXTENDED_DATA_CURRENT_SPEED, speed); // Broadcasts the Intent to receivers in this app. LocalBroadcastManager.getInstance(this).sendBroadcast(localIntent); Log.i(LOG_TAG, "New speed is " + speed + "m/sec " + speed * 3.6 + "km/h" ); }
values.put(TrackContentProvider.Schema.COL_ACCURACY, location.getAccuracy()); if (location.hasSpeed()) { values.put(TrackContentProvider.Schema.COL_SPEED, location.getSpeed());
/** * Write location to database. * * @param loc Location */ void writeLocation(Location loc) { if (Logger.DEBUG) { Log.d(TAG, "[writeLocation]"); } ContentValues values = new ContentValues(); values.put(DbContract.Positions.COLUMN_TIME, loc.getTime() / 1000); values.put(DbContract.Positions.COLUMN_LATITUDE, loc.getLatitude()); values.put(DbContract.Positions.COLUMN_LONGITUDE, loc.getLongitude()); if (loc.hasBearing()) { values.put(DbContract.Positions.COLUMN_BEARING, loc.getBearing()); } if (loc.hasAltitude()) { values.put(DbContract.Positions.COLUMN_ALTITUDE, loc.getAltitude()); } if (loc.hasSpeed()) { values.put(DbContract.Positions.COLUMN_SPEED, loc.getSpeed()); } if (loc.hasAccuracy()) { values.put(DbContract.Positions.COLUMN_ACCURACY, loc.getAccuracy()); } values.put(DbContract.Positions.COLUMN_PROVIDER, loc.getProvider()); db.insert(DbContract.Positions.TABLE_NAME, null, values); }
if ((test.hasSpeed()) && (test.getSpeed() < GeometryUtils.MIN_SPEED || test.getSpeed() > GeometryUtils.MAX_SPEED)) { Log.w(TAG, "Speed out-of-range [" + GeometryUtils.MIN_SPEED + ".." + GeometryUtils.MAX_SPEED + "]:" + test.getSpeed()); return false;
/** * Remove noise from the measurement of the location. * @param loc a location * @return Answer <code>false</code> iff the location should not be used. */ private boolean filterNoise(final Location loc) { if( ! loc.hasSpeed() ) return true; if( this.recentSpeeds.isEmpty() ) { // rescentSpeeds is a queue of locations this.recentSpeeds.add(loc); return true; } final Location lastFix = this.recentSpeeds.getHead(); final long delta_t = (loc.getTime() - lastFix.getTime()) / 1000; if( delta_t == 0 ) return false; final float delta_v = loc.getSpeed() - lastFix.getSpeed(); final float a = delta_v / delta_t; if( Math.abs(a) <= AccelThreshold ) { this.recentSpeeds.add(loc); return true; } return false; }
@Override public void onLocationChanged(Location location) { if (location.hasAccuracy()) { SpannableString s = new SpannableString(String.format("%.0f", location.getAccuracy()) + "m"); s.setSpan(new RelativeSizeSpan(0.75f), s.length()-1, s.length(), 0); accuracy.setText(s); if (firstfix){ status.setText(""); fab.setVisibility(View.VISIBLE); if (!data.isRunning() && !maxSpeed.getText().equals("")) { refresh.setVisibility(View.VISIBLE); } firstfix = false; } }else{ firstfix = true; } if (location.hasSpeed()) { progressBarCircularIndeterminate.setVisibility(View.GONE); String speed = String.format(Locale.ENGLISH, "%.0f", location.getSpeed() * 3.6) + "km/h"; if (sharedPreferences.getBoolean("miles_per_hour", false)) { // Convert to MPH speed = String.format(Locale.ENGLISH, "%.0f", location.getSpeed() * 3.6 * 0.62137119) + "mi/h"; } SpannableString s = new SpannableString(speed); s.setSpan(new RelativeSizeSpan(0.25f), s.length()-4, s.length(), 0); currentSpeed.setText(s); } }
/** * Create a new SerialziableLocation with the values of the given Location. */ public SerializableLocation(Location location) { this.latitude = location.getLatitude(); this.longitude = location.getLongitude(); this.accuracy = location.getAccuracy(); this.altitude = location.getAltitude(); this.bearing = location.getBearing(); this.provider = location.getProvider(); this.speed = location.getSpeed(); this.time = location.getTime(); this.hasAccuracy = location.hasAccuracy(); this.hasAltitude = location.hasAltitude(); this.hasBearing = location.hasBearing(); this.hasSpeed = location.hasSpeed(); }
@Implementation public void set(Location l) { time = l.getTime(); provider = l.getProvider(); latitude = l.getLatitude(); longitude = l.getLongitude(); accuracy = l.getAccuracy(); bearing = l.getBearing(); altitude = l.getAltitude(); speed = l.getSpeed(); hasAccuracy = l.hasAccuracy(); hasAltitude = l.hasAltitude(); hasBearing = l.hasBearing(); hasSpeed = l.hasSpeed(); }
@Implementation public void set(Location l) { time = l.getTime(); provider = l.getProvider(); latitude = l.getLatitude(); longitude = l.getLongitude(); accuracy = l.getAccuracy(); bearing = l.getBearing(); altitude = l.getAltitude(); speed = l.getSpeed(); hasAccuracy = l.hasAccuracy(); hasAltitude = l.hasAltitude(); hasBearing = l.hasBearing(); hasSpeed = l.hasSpeed(); }
if (loc.hasSpeed() && (loc.getSpeed() == 0)) loc.removeBearing(); // Removes bearing if the speed is zero LocationExtended eloc = new LocationExtended(loc); eloc.setNumberOfSatellites(getNumberOfSatellites()); if ((PrevFix != null) && (PrevFix.getLocation().hasSpeed()) && (eloc.getLocation().hasSpeed()) && (GPSStatus == GPS_OK) && (Recording) && (((eloc.getLocation().getSpeed() == 0) && (PrevFix.getLocation().getSpeed() != 0)) || ((eloc.getLocation().getSpeed() != 0) && (PrevFix.getLocation().getSpeed() == 0)))) { if (!isPrevFixRecorded) { // Record the old sample if not already recorded
message.setAlt((int)currentLocation.getAltitude()); message.setAcc(Math.round(currentLocation.getAccuracy())); if (currentLocation.hasSpeed()) { message.setVelocity((int)(currentLocation.getSpeed() * 3.6)); // Convert m/s to km/h
public void onLocationChanged(Location location) { data = MainActivity.getData(); if (data.isRunning()){ currentLat = location.getLatitude(); currentLon = location.getLongitude(); if (data.isFirstTime()){ lastLat = currentLat; lastLon = currentLon; data.setFirstTime(false); } lastlocation.setLatitude(lastLat); lastlocation.setLongitude(lastLon); double distance = lastlocation.distanceTo(location); if (location.getAccuracy() < distance){ data.addDistance(distance); lastLat = currentLat; lastLon = currentLon; } if (location.hasSpeed()) { data.setCurSpeed(location.getSpeed() * 3.6); if(location.getSpeed() == 0){ new isStillStopped().execute(); } } data.update(); updateNotification(true); } }
if (mLastLocation.hasSpeed()) location.setSpeed(mLastLocation.getSpeed());