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


Java Location.hasAccuracy方法代码示例

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


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

示例1: onLocationChanged

import android.location.Location; //导入方法依赖的package包/类
@Override
public void onLocationChanged(Location location) {
  if (!location.hasAccuracy()) {
    Log.e("Received a location with no accuracy.");
    return;
  }

  // Currently, location segment treats GPS and CELL the same. In the future, we might want more
  // distinction in the accuracy types. For example, a customer might want to send messages only
  // to the ones with very accurate location information. We are assuming that it is from GPS if
  // the location accuracy is less than or equal to |ACCURACY_THRESHOLD_GPS|.
  LeanplumLocationAccuracyType locationAccuracyType =
      location.getAccuracy() >= ACCURACY_THRESHOLD_GPS ?
          LeanplumLocationAccuracyType.CELL : LeanplumLocationAccuracyType.GPS;

  if (!isSendingLocation && needToSendLocation(locationAccuracyType)) {
    try {
      setUserAttributesForLocationUpdate(location, locationAccuracyType);
    } catch (Throwable t) {
      Util.handleException(t);
    }
  }

  LocationServices.FusedLocationApi.removeLocationUpdates(googleApiClient, this);
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:26,代码来源:LocationManagerImplementation.java

示例2: InformListenerOfStatus

import android.location.Location; //导入方法依赖的package包/类
private void InformListenerOfStatus(Location newLoc) {
    if (m_Listener == null)
        return;

    if (newLoc == null) {
        m_Listener.UpdateStatus(GPSQuality.Unknown, IsFlying, null, IsRecording);
        return;
    }

    GPSQuality q = GPSQuality.Unknown;
    if (newLoc.hasAccuracy()) {
        float Accuracy = newLoc.getAccuracy();
        if (Accuracy <= 0.0 || Accuracy > MFBConstants.MIN_ACCURACY)
            q = GPSQuality.Poor;
        else
            q = (Accuracy < (MFBConstants.MIN_ACCURACY / 2.0)) ? GPSQuality.Excellent : GPSQuality.Good;
    }

    m_Listener.UpdateStatus(q, IsFlying, newLoc, IsRecording);
}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:21,代码来源:MFBLocation.java

示例3: skipLocation

import android.location.Location; //导入方法依赖的package包/类
/**
 * Should the location be logged or skipped
 * @param loc Location
 * @return True if skipped
 */
private boolean skipLocation(Location loc) {
    // accuracy radius too high
    if (loc.hasAccuracy() && loc.getAccuracy() > maxAccuracy) {
        if (Logger.DEBUG) { Log.d(TAG, "[location accuracy above limit: " + loc.getAccuracy() + " > " + maxAccuracy + "]"); }
        // reset gps provider to get better accuracy even if time and distance criteria don't change
        if (loc.getProvider().equals(LocationManager.GPS_PROVIDER)) {
            restartUpdates();
        }
        return true;
    }
    // use network provider only if recent gps data is missing
    if (loc.getProvider().equals(LocationManager.NETWORK_PROVIDER) && lastLocation != null) {
        // we received update from gps provider not later than after maxTime period
        long elapsedMillis = SystemClock.elapsedRealtime() - lastUpdateRealtime;
        if (lastLocation.getProvider().equals(LocationManager.GPS_PROVIDER) && elapsedMillis < maxTimeMillis) {
            // skip network provider
            if (Logger.DEBUG) { Log.d(TAG, "[location network provider skipped]"); }
            return true;
        }
    }
    return false;
}
 
开发者ID:bfabiszewski,项目名称:ulogger-android,代码行数:28,代码来源:LoggerService.java

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

示例5: notifyLocationUpdated

import android.location.Location; //导入方法依赖的package包/类
private void notifyLocationUpdated(Location location, Context context) {
    Location home = settings.getHomeLocation();
    double distance = -1;
    if (home != null)
        distance = home.distanceTo(location);

    String accuracyString = (location.hasAccuracy() ? String.valueOf(location.getAccuracy()) : "?");
    String message = String.format(Locale.getDefault(), "Accuracy: %s Distance: %.2f", accuracyString, distance);
    ToastLog.logLong(context, TAG, message);
}
 
开发者ID:bsautermeister,项目名称:GeoFencer,代码行数:11,代码来源:TimedGPSFixReceiver.java

示例6: fromLocation

import android.location.Location; //导入方法依赖的package包/类
public static GeoLocation fromLocation(Location location) {
    Pair<Long, Long> coords = MapUtils.WGS84toETRSTM35FIN(location.getLatitude(), location.getLongitude());

    GeoLocation geoLocation = new GeoLocation();
    geoLocation.latitude = coords.first.intValue();
    geoLocation.longitude = coords.second.intValue();
    if (location.hasAccuracy()) {
        geoLocation.accuracy = (double) location.getAccuracy();
    }
    if (location.hasAltitude()) {
        geoLocation.altitude = location.getAltitude();
    }
    return geoLocation;
}
 
开发者ID:suomenriistakeskus,项目名称:oma-riista-android,代码行数:15,代码来源:GeoLocation.java

示例7: addAccuracyIfPresent

import android.location.Location; //导入方法依赖的package包/类
private void addAccuracyIfPresent(Location location, LocationEvent locationEvent) {
  if (location.hasAccuracy()) {
    float accuracyRounded = Math.round(location.getAccuracy());
    locationEvent.setAccuracy(accuracyRounded);
  }
}
 
开发者ID:mapbox,项目名称:mapbox-events-android,代码行数:7,代码来源:LocationMapper.java

示例8: checkIfLocationIsPoint

import android.location.Location; //导入方法依赖的package包/类
public static boolean checkIfLocationIsPoint(Location location, AtPoint atPoint) {
    Log.d(TAG, "checkIfLocationIsPoint");
    
    double percentageRadius = (int)(atPoint.getRadius()*(LocationService.getToleranceRadius()/100.0f));
    
    boolean isPoint = false;
    double toleranceRadius = percentageRadius + atPoint.getRadius();
    double minimumAccuracy = LocationService.getMinimumAccuracy();
    double locationAccuracy = 0;
    
    // Minimum precision meters required to enable the check
    if (location.hasAccuracy() && location.getAccuracy() <= minimumAccuracy) {
        locationAccuracy = location.getAccuracy();
    } else {
        // Since there is no accuracy it means the localization won't be as precise as it should be.
        toleranceRadius += minimumAccuracy;
    }
    
    
    double nextLat = atPoint.getLat();
    double nextLon = atPoint.getLon();
    double lat = location.getLatitude();
    double lon = location.getLongitude();
    float[] results = new float[1];
    
    // Calculating the distance with a class Location method
    location.distanceBetween(lat, lon, nextLat, nextLon, results);
    double distance = results[0];
    
    // Updating the current distance from the Goal
    //LocationService.setDistanceFromGoal(distance);
    
    // Logging  - Only for 1 Point or i go CRAZY
    
    /*
        Prato Della Valle: 45.398436, 11.876532
        
        Punto > 100m 45.397682, 11.878960
        Punto >= 100m  45.397926, 11.877744
        Punto < 100m 45.398619, 11.877774
        
        Colonna Segno Zod: 45.407837, 11.873059
        
        Punto > 5m: 45.407751, 11.873092
        Punto >= 5m: 45.407878, 11.873215
        Punto < 5m:  45.407819, 11.873115
    
    
    */
    if( Utils.DEBUG_ACTIVE ) {
        // Better to filter for just one point, or it's kinda spammy
        if (atPoint.getIdPoint() == 24) {
            Log.d(TAG, "\nDEBUG_LOCALIZATION");
            Log.d(TAG, "\nDEBUG_LOCALIZATION Coordinates Player: " + lat + ", " + lon);
            Log.d(TAG, "\nDEBUG_LOCALIZATION Coordinates Point: " + nextLat + ", " + nextLon);
            Log.d(TAG, "\nDEBUG_LOCALIZATION Accuracy: " + locationAccuracy);
            Log.d(TAG, "\nDEBUG_LOCALIZATION Service min.acc = " + LocationService.getMinimumAccuracy());
            Log.d(TAG, "\nDEBUG_LOCALIZATION Tolerance Service: " + LocationService.getToleranceRadius());
            Log.d(TAG, "\nDEBUG_LOCALIZATION Tolerance Point: " + atPoint.getRadius());
            Log.d(TAG, "\nDEBUG_LOCALIZATION AddedRadius%: " + percentageRadius);
            Log.d(TAG, "\nDEBUG_LOCALIZATION ToleranceRadius: " + toleranceRadius);
            Log.d(TAG, "\nDEBUG_LOCALIZATION Distance R0 " + results[0]);
            Log.d(TAG, "\nDEBUG_LOCALIZATION toleranceRadius > distance?");
        }
    }


    if (distance < toleranceRadius) {
        Log.i(TAG, "Point reached!!");
        isPoint = true;
        if( Utils.DEBUG_ACTIVE ) {
            Log.d(TAG, "\nDEBUG_LOCALIZATION YEP");
        }
    }
    
    return isPoint;
}
 
开发者ID:stefanonicolai,项目名称:AstronomyTourPadova,代码行数:78,代码来源:AtUtils.java

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