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


Java Location.hasSpeed方法代码示例

本文整理汇总了Java中android.location.Location.hasSpeed方法的典型用法代码示例。如果您正苦于以下问题:Java Location.hasSpeed方法的具体用法?Java Location.hasSpeed怎么用?Java Location.hasSpeed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.location.Location的用法示例。


在下文中一共展示了Location.hasSpeed方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: getCurrent

import android.location.Location; //导入方法依赖的package包/类
@Override
public String getCurrent() {
    if (infoCollector != null) {
        String locationSpeedString = "";
        final Location loc = infoCollector.getLocationInfo();
        if (loc != null && loc.hasSpeed() && Helperfunctions.getAge(loc) < 3000000000L) {
            locationSpeedString = String.format("%.1f %s", loc.getSpeed() * 3.6d, context.getResources().getString(R.string.test_location_km_h));
        } else {
            locationSpeedString = context.getString(R.string.not_available);
        }

        return locationSpeedString;
    }

    return null;
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:17,代码来源:LocationSpeedItem.java

示例3: convertNmeaRMC

import android.location.Location; //导入方法依赖的package包/类
public static String convertNmeaRMC(Location paramLocation) {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("$GPRMC,");
    localStringBuilder.append(FormatUTCDate("HHmmss.SSS", new Date(paramLocation.getTime())));
    localStringBuilder.append(",A,");
    localStringBuilder.append(FormatLatLon("%02d%08.5f,%c,", 'S', 'N', paramLocation.getLatitude()));
    localStringBuilder.append(FormatLatLon("%03d%08.5f,%c,", 'W', 'E', paramLocation.getLongitude()));
    if (paramLocation.hasSpeed()) {
        localStringBuilder.append(String.format(Locale.getDefault(), "%5.3f", paramLocation.getSpeed() / 0.5395720670123687D));
    }
    localStringBuilder.append(",");
    if (paramLocation.hasBearing()) {
        localStringBuilder.append(String.format(Locale.getDefault(), "%1.0f", (double) paramLocation.getBearing()));
    }
    localStringBuilder.append(",");
    localStringBuilder.append(FormatUTCDate("ddMMyy", new Date(paramLocation.getTime())));
    localStringBuilder.append(",,,A");
    localStringBuilder.append(calcNmeaCrc(localStringBuilder));
    return localStringBuilder.toString();
}
 
开发者ID:MaoJianwei,项目名称:Android_GPS_NMEA_Server_Reader_Sender,代码行数:21,代码来源:MaoNmeaTools.java

示例4: convertNmeaVTG

import android.location.Location; //导入方法依赖的package包/类
public static String convertNmeaVTG(Location paramLocation) {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("$GPVTG,");
    if (paramLocation.hasBearing()) {
        localStringBuilder.append(String.format(Locale.getDefault(), "%1.0f", paramLocation.getBearing()));
    }
    localStringBuilder.append(",T,,M,");
    if (paramLocation.hasSpeed()) {
        localStringBuilder.append(String.format(Locale.getDefault(), "%5.3f,N,%5.3f,K,",
                paramLocation.getSpeed() / 0.5395720670123687D, 3.6D * paramLocation.getSpeed()));
    } else {
        localStringBuilder.append(",,,,");
    }
    localStringBuilder.append(calcNmeaCrc(localStringBuilder));
    return localStringBuilder.toString();
}
 
开发者ID:MaoJianwei,项目名称:Android_GPS_NMEA_Server_Reader_Sender,代码行数:17,代码来源:MaoNmeaTools.java

示例5: writeLocation

import android.location.Location; //导入方法依赖的package包/类
/**
 * 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);
}
 
开发者ID:bfabiszewski,项目名称:ulogger-android,代码行数:28,代码来源:DbAccess.java

示例6: 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

示例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: onLocationChanged

import android.location.Location; //导入方法依赖的package包/类
@Override
public void onLocationChanged(final Location location) {
    LogHelper.debugLog(TAG,
            "File name: \"" +
                    Thread.currentThread().getStackTrace()[2].getFileName() +
                    "\", Line number: " +
                    Thread.currentThread().getStackTrace()[2].getLineNumber() +
                    ", Class name: \"" +
                    Thread.currentThread().getStackTrace()[2].getClassName() +
                    "\", Method name: \"" +
                    Thread.currentThread().getStackTrace()[2].getMethodName() +
                    "\"");

    LogHelper.infoLog(TAG, "Location changed: " + location);

    LogHelper.infoLog(TAG, "Changed location provider: " + location.getProvider());

    LogHelper.infoLog(TAG, "Changed location latitude: " + location.getLatitude());

    LogHelper.infoLog(TAG, "Changed location longitude: " + location.getLongitude());

    LogHelper.infoLog(TAG, "Changed location time: " + location.getTime());

    LogHelper.infoLog(TAG, "Changed location elapsed realtime nanos: " + location.getElapsedRealtimeNanos());

    LogHelper.infoLog(TAG, "Changed location extras: " + location.getExtras());

    if (location.hasAccuracy()) {
        LogHelper.infoLog(TAG, "Changed location has accuracy: " + location.getAccuracy() + " m");
    }

    if (location.hasAltitude()) {
        LogHelper.infoLog(TAG, "Changed location has altitude: " + location.getAltitude() + " m");
    }

    if (location.hasBearing()) {
        LogHelper.infoLog(TAG, "Changed location has bearing: " + location.getBearing() + " °");
    }

    if (location.hasSpeed()) {
        LogHelper.infoLog(TAG, "Changed location has speed: " + location.getSpeed() + " m/s");
    }

    Intent intent = new Intent(ACTION_LOCATION_BROADCAST);
    intent.putExtra(EXTRA_PROVIDER, location.getProvider());
    intent.putExtra(EXTRA_LATITUDE, location.getLatitude());
    intent.putExtra(EXTRA_LONGITUDE, location.getLongitude());
    intent.putExtra(EXTRA_TIME, location.getTime());
    intent.putExtra(EXTRA_ELAPSED_REALTIME_NANOS, location.getElapsedRealtimeNanos());
    intent.putExtra(EXTRA_EXTRAS, location.getExtras());
    intent.putExtra(EXTRA_ACCURACY, location.getAccuracy());
    intent.putExtra(EXTRA_ALTITUDE, location.getAltitude());
    intent.putExtra(EXTRA_BEARING, location.getBearing());
    intent.putExtra(EXTRA_SPEED, location.getSpeed());

    LocalBroadcastManager.getInstance(this).sendBroadcast(intent);

    try {
        mRealm.executeTransaction(new Realm.Transaction() {
            @Override
            public void execute(Realm realm) {
                LocationRealmObject locationRealmObject = realm.createObject(LocationRealmObject.class);
                locationRealmObject.setProvider(location.getProvider());
                locationRealmObject.setLatitude(location.getLatitude());
                locationRealmObject.setLongitude(location.getLongitude());
                locationRealmObject.setTime(location.getTime());
                locationRealmObject.setElapsedRealtimeNanos(location.getElapsedRealtimeNanos());
                locationRealmObject.setAccuracy(location.getAccuracy());
                locationRealmObject.setAltitude(location.getAltitude());
                locationRealmObject.setBearing(location.getBearing());
                locationRealmObject.setSpeed(location.getSpeed());
            }
        });
    } catch (Exception e) {
        LogHelper.errorLog(TAG, e.getMessage());
        e.printStackTrace();
    }
}
 
开发者ID:n37bl4d3,项目名称:Android-Location-Tracker,代码行数:79,代码来源:LocationService.java


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