本文整理汇总了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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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();
}
}