本文整理汇总了Java中android.location.Location.getSpeed方法的典型用法代码示例。如果您正苦于以下问题:Java Location.getSpeed方法的具体用法?Java Location.getSpeed怎么用?Java Location.getSpeed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Location
的用法示例。
在下文中一共展示了Location.getSpeed方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onLocationChanged(Location location) {
// save for later analysis
gpx.appendData(location);
// for display during tracking and calculating of averages on the device
if(lastLoc == null){
lastLoc = location;
}
++numberOfPoints;
speedSum += location.getSpeed();
distance += location.distanceTo(lastLoc);
lastLoc = location;
if(firstLocation) {
// now that we have our first data point, we can update the GUI without throwing a NullPointerException
firstLocation = false;
Timer timer = new Timer();
timer.scheduleAtFixedRate(updateInterfaceTask, 0, 1000);
}
}
示例2: updateAcceleration
import android.location.Location; //导入方法依赖的package包/类
/**
* Update the acceleration using the velocity and time elapsed.
*
* @param location new location
*/
synchronized private void updateAcceleration(Location location) {
if (location.hasSpeed()) {
if (!hasVelocity) {
mVelocity = location.getSpeed();
mTime = System.currentTimeMillis();
hasVelocity = true;
} else {
float velocity = location.getSpeed();
long currentTime = System.currentTimeMillis();
float acceleration = (velocity - mVelocity) / (currentTime - mTime) * 1000;
BigDecimal accelerationRounded = new BigDecimal(acceleration).setScale(2, BigDecimal.ROUND_HALF_UP);
mAcceleration = accelerationRounded.floatValue();
mVelocity = velocity;
mTime = currentTime;
hasAcceleration = true;
}
}
}
示例3: LocationInfo
import android.location.Location; //导入方法依赖的package包/类
LocationInfo(Location location) {
latitude = location.getLatitude();
longitude = location.getLongitude();
horizontalAccuracy = location.getAccuracy();
timeStampSecs = TimeUnit.MILLISECONDS.toSeconds(location.getTime());
speed = location.getSpeed();
course = location.getBearing();
altitude = location.getAltitude();
}
示例4: getFuturePosition
import android.location.Location; //导入方法依赖的package包/类
/**
* uses dead reckoning to find the users future location.
*
* @return a {@link Point}
* @since 0.2.0
*/
private static Point getFuturePosition(Location location, MapboxNavigationOptions options) {
// Find future location of user
Point locationToPosition = Point.fromLngLat(location.getLongitude(), location.getLatitude());
double metersInFrontOfUser = location.getSpeed() * options.deadReckoningTimeInterval();
return TurfMeasurement.destination(
locationToPosition, metersInFrontOfUser, location.getBearing(), TurfConstants.UNIT_METERS
);
}
示例5: validLocationUpdate
import android.location.Location; //导入方法依赖的package包/类
/**
* Runs several checks on the actual rawLocation object itself in order to ensure that we are
* performing navigation progress on a accurate/valid rawLocation update.
*/
@SuppressWarnings("MissingPermission")
private boolean validLocationUpdate(Location location) {
if (locationEngine.getLastLocation() == null) {
return true;
}
// If the locations the same as previous, no need to recalculate things
return !(location.equals(locationEngine.getLastLocation())
|| (location.getSpeed() <= 0 && location.hasSpeed())
|| location.getAccuracy() >= 100);
}
示例6: updateLocInfo
import android.location.Location; //导入方法依赖的package包/类
void updateLocInfo (Location location) {
if (location != null) {
float latitude = (float) location.getLatitude();
float longitude = (float) location.getLongitude();
float altitude = (float) location.getAltitude();
float altitude_feet = altitude * 3.28f;
float speed = (float) location.getSpeed();
float speed_knots = speed*1.94f;
String latitude_str = String.format("%.1f", Math.abs(latitude)) + '°' + (latitude >= 0 ? 'N' : 'S');
String longitude_str = String.format("%.1f", Math.abs(longitude)) + '°' + (longitude >= 0 ? 'E' : 'W');
String altitude_str, altitude_feet_str;
if (altitude > 1000) altitude_str = String.format("%.1f",(altitude/1000f)) + " km";
else altitude_str = String.format("%.1f",altitude) + " m";
if (altitude_feet > 1000) altitude_feet_str = String.format("%.1f",(altitude_feet/1000f)) + "k feet";
else altitude_feet_str = String.format("%.1f",altitude_feet) + " feet";
String speed_str = (int)speed + " m/s";
String speed_knots_str = (int)speed_knots + " knots";
loc_out.setText(latitude_str + " " + longitude_str + "\n\n"+
altitude_str + " " + altitude_feet_str + "\n\n"+
speed_str + " " + speed_knots_str);
if (loc_log) {
loc_pw.println(df.format(new Date())+" "+latitude_str+" "+longitude_str+" "+altitude_str+" "+speed_str);
}
}
}
示例7: calculateMph
import android.location.Location; //导入方法依赖的package包/类
private void calculateMph(Location location) {
if (location.hasSpeed()) {
int speed = (int) (location.getSpeed() * MPH_DOUBLE);
mphText.setText(String.valueOf(speed));
} else {
mphText.setText(String.valueOf(0));
}
}
示例8: LocSample
import android.location.Location; //导入方法依赖的package包/类
LocSample(Location l) {
super();
Latitude = l.getLatitude();
Longitude = l.getLongitude();
Alt = (int) (l.getAltitude() * MFBConstants.METERS_TO_FEET);
Speed = l.getSpeed() * MFBConstants.MPS_TO_KNOTS;
HError = l.getAccuracy();
TimeStamp.setTime(l.getTime());
TZOffset = 0;
}
示例9: LocationRecord
import android.location.Location; //导入方法依赖的package包/类
public LocationRecord(Location location) {
super(new RecordInfo(location.getAccuracy(), location.getTime()));
this.latitude = location.getLatitude();
this.longitude = location.getLongitude();
this.altitude = location.getAltitude();
this.speed = location.getSpeed();
this.bearing = location.getBearing();
}
示例10: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
@Override
// This sets fields longitude, latitude, altitude, hasLocationData, and
// hasAltitude, then calls LocationSensor.LocationChanged(), all in the
// enclosing class LocationSensor.
public void onLocationChanged(Location location) {
lastLocation = location;
longitude = location.getLongitude();
latitude = location.getLatitude();
speed = location.getSpeed();
// If the current location doesn't have altitude information, the prior
// altitude reading is retained.
if (location.hasAltitude()) {
hasAltitude = true;
altitude = location.getAltitude();
}
// By default Location.latitude == Location.longitude == 0.
// So we want to ignore that case rather than generating a changed event.
if (longitude != UNKNOWN_VALUE || latitude != UNKNOWN_VALUE) {
hasLocationData = true;
final double argLatitude = latitude;
final double argLongitude = longitude;
final double argAltitude = altitude;
final float argSpeed = speed;
androidUIHandler.post(new Runnable() {
@Override
public void run() {
LocationChanged(argLatitude, argLongitude, argAltitude, argSpeed);
}
});
}
}
示例11: checkInterval
import android.location.Location; //导入方法依赖的package包/类
private void checkInterval(Location location) {
if (location == null) {
return;
}
if (!isValidState()) {
distanceInterval = 0;
recentSpeed = 0;
return;
}
recentSpeed = location.getSpeed();
if (!isValidSpeed()) {
return;
}
double distance = 0;
if (prevLatitude != location.getLatitude()
|| prevLongitude != location.getLongitude()) {
distance = calcDistance(location);
}
// enable fake speed for tests:
if (BuildConfig.FAKE) {
distance += 20;
}
prevLatitude = location.getLatitude();
prevLongitude = location.getLongitude();
prevAltitude = location.getAltitude();
if (distance < intervalLength) {
distanceInterval += distance;
} else {
sendOnIntervalChanged(distanceInterval, false);
distanceInterval = 0;
return;
}
if (distanceInterval >= intervalLength) {
boolean correctData = distanceInterval < MAX_DISTANCE;
sendOnIntervalChanged(distanceInterval, correctData);
distanceInterval = 0;
}
}
示例12: checkIsDataAvailableForRecord
import android.location.Location; //导入方法依赖的package包/类
private boolean checkIsDataAvailableForRecord() {
GPSDetector gpsDetector = getGPSDetector();
if (gpsDetector == null ||
!gpsDetector.isValidSpeed() || !gpsDetector.isValidState()) {
return false;
}
Location loc = gpsDetector.getLocation();
if (loc == null) {
return false;
}
double latitude = loc.getLatitude();
double longitude = loc.getLongitude();
double altitude = loc.getAltitude();
curSpeed = loc.getSpeed();
double distance = 0;
if (latitude >= 0 && longitude >= 0) {
distance = calcDistance(latitude, longitude);
if (curLatitude != latitude && curLongitude != longitude) {
curLatitude = latitude;
curLongitude = longitude;
curAltitude = altitude;
//Log.d(TAG, "curLatitude= " + curLatitude + ", curLongitude= "
//+ curLongitude + ", distance= " + distance);
}
}
if (distance >= MIN_DISTANCE) {
curDistance = distance;
Log.d(TAG, "data available for record, distance= " + distance);
return true;
}
return false;
}
示例13: validLocationToSnap
import android.location.Location; //导入方法依赖的package包/类
public boolean validLocationToSnap(Location location) {
// If users not moving, don't snap their position or bearing
return location.getSpeed() > 0d;
}