当前位置: 首页>>代码示例>>Java>>正文


Java Location.getSpeed方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:renatobellotti,项目名称:FreeRun,代码行数:24,代码来源:TrackingActivity.java

示例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;
        }
    }
}
 
开发者ID:w86763777,项目名称:BikeLine,代码行数:25,代码来源:GPSService.java

示例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();
}
 
开发者ID:OpenLocate,项目名称:openlocate-android,代码行数:10,代码来源:OpenLocateLocation.java

示例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
  );
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:15,代码来源:OffRouteDetector.java

示例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);
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:15,代码来源:NavigationService.java

示例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);
        }
    }
}
 
开发者ID:aryadas98,项目名称:CockpitInfo,代码行数:32,代码来源:MainActivity.java

示例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));
  }
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-hud-demo,代码行数:9,代码来源:DisplayActivity.java

示例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;
}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:11,代码来源:LocSample.java

示例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();
}
 
开发者ID:ubikgs,项目名称:AndroidSensors,代码行数:9,代码来源:LocationRecord.java

示例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);
        }
      });
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:33,代码来源:LocationSensor.java

示例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;
        }
    }
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:39,代码来源:GPSDetector.java

示例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;
}
 
开发者ID:WorldBank-Transport,项目名称:RoadLab-Pro,代码行数:33,代码来源:GeoTagTracker.java

示例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;
}
 
开发者ID:mapbox,项目名称:mapbox-navigation-android,代码行数:5,代码来源:Snap.java


注:本文中的android.location.Location.getSpeed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。