當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。