本文整理汇总了Java中android.location.Location.getAccuracy方法的典型用法代码示例。如果您正苦于以下问题:Java Location.getAccuracy方法的具体用法?Java Location.getAccuracy怎么用?Java Location.getAccuracy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Location
的用法示例。
在下文中一共展示了Location.getAccuracy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLastKnownLocation
import android.location.Location; //导入方法依赖的package包/类
/**
* Gets last known location
* Use only when current location is not available
* @param context Context is required to acquire LocationManager system service
* @return Returns last known location as android.location.Location
*/
public static Location getLastKnownLocation(Context context) {
LocationManager mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
List<String> providers = mLocationManager.getProviders(true);
Location bestLocation = null;
if (providers == null || providers.size() == 0) return null;
try {
for (String provider : providers) {
if (provider.equals(LocationManager.PASSIVE_PROVIDER)) continue;
Location l = mLocationManager.getLastKnownLocation(provider);
if (l == null) continue;
if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) bestLocation = l;
}
} catch (SecurityException ignored) {}
return bestLocation;
}
示例2: getLastKnownLocation
import android.location.Location; //导入方法依赖的package包/类
private Location getLastKnownLocation() {
mLocationManager = (LocationManager)InstrumentationRegistry.getTargetContext().getSystemService(LOCATION_SERVICE);
List<String> providers = mLocationManager.getProviders(true);
Location bestLocation = null;
for (String provider : providers) {
Location loc;
try{
loc = mLocationManager.getLastKnownLocation(provider);
} catch (SecurityException e) {
loc = null;
}
if (loc == null) {
continue;
}
if (bestLocation == null || loc.getAccuracy() < bestLocation.getAccuracy()) {
// Found best last known location: %s", l);
bestLocation = loc;
}
}
return bestLocation;
}
示例3: getBestLastKnownLocation
import android.location.Location; //导入方法依赖的package包/类
/**
* Restituice la posizione più accurata e più recente del dispositivo, scelta tra tutti i location provider disponibili.
*/
public static Location getBestLastKnownLocation(Context context) {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
List<String> providers = locationManager.getAllProviders();
Location bestLocation = null;
for (String provider : providers) {
try {
Location location = locationManager.getLastKnownLocation(provider);
if (bestLocation == null || location != null
&& location.getElapsedRealtimeNanos() > bestLocation.getElapsedRealtimeNanos()
&& location.getAccuracy() > bestLocation.getAccuracy())
bestLocation = location;
} catch (SecurityException ignored) {
}
}
return bestLocation;
}
示例4: getLastKnownLocation
import android.location.Location; //导入方法依赖的package包/类
/**
* Get last known location as in http://stackoverflow.com/questions/20438627/getlastknownlocation-returns-null
* @return the last location known to the device
*/
private Location getLastKnownLocation() {
LocationManager mLocationManager = (LocationManager)getApplicationContext().getSystemService(LOCATION_SERVICE);
List<String> providers = mLocationManager.getProviders(true);
Location bestLocation = null;
for (String provider : providers) {
Location l = mLocationManager.getLastKnownLocation(provider);
if (l == null) {
continue;
}
if (bestLocation == null || l.getAccuracy() < bestLocation.getAccuracy()) {
// Found best last known location: %s", l);
bestLocation = l;
}
}
return bestLocation;
}
示例5: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onLocationChanged(Location location) {
if (location == null || locationQueryCancelRunnable == null) {
return;
}
FileLog.e("tmessages", "found location " + location);
lastKnownLocation = location;
if (location.getAccuracy() < 100) {
if (delegate != null) {
delegate.onLocationAcquired(location);
}
if (locationQueryCancelRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(locationQueryCancelRunnable);
}
cleanup();
}
}
示例6: locationCompatibleWithGroup
import android.location.Location; //导入方法依赖的package包/类
/**
* Check to see if the coverage area (location) of an RF emitter is close
* enough to others in a group that we can believably add it to the group.
* @param location The coverage area of the candidate emitter
* @param locGroup The coverage areas of the emitters already in the group
* @param radius The coverage radius expected for they type of emitter
* we are dealing with.
* @return
*/
private boolean locationCompatibleWithGroup(Location location,
Set<Location> locGroup,
double radius) {
// If the location is within range of all current members of the
// group, then we are compatible.
for (Location other : locGroup) {
double testDistance = (location.distanceTo(other) -
location.getAccuracy() -
other.getAccuracy());
if (testDistance > radius) {
return false;
}
}
return true;
}
示例7: add
import android.location.Location; //导入方法依赖的package包/类
public void add(Location loc, double weight) {
if (loc == null)
return;
reportAccuracy = loc.getAccuracy();
count++;
//Log.d(TAG,"add() entry: weight="+weight+", count="+count);
double lat = loc.getLatitude();
wSumLat = wSumLat + weight;
wSum2Lat = wSum2Lat + (weight * weight);
double oldMean = meanLat;
meanLat = oldMean + (weight / wSumLat) * (lat - oldMean);
sLat = sLat + weight * (lat - oldMean) * (lat - meanLat);
double lon = loc.getLongitude();
wSumLon = wSumLon + weight;
wSum2Lon = wSum2Lon + (weight * weight);
oldMean = meanLon;
meanLon = oldMean + (weight / wSumLon) * (lon - oldMean);
sLon = sLon + weight * (lon - oldMean) * (lon - meanLon);
timeMs = loc.getTime();
}
示例8: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onLocationChanged(Location location) {
// Don't update position with gps position if pre-existing entry or location has already been set.
if (getView() != null && mEvent.mLocalId <= 0
&& (mEvent.mLocationSource == null || mEvent.mLocationSource.equals(GameHarvest.LOCATION_SOURCE_GPS))) {
mEvent.mLocation = location;
mEvent.mAccuracy = location.getAccuracy();
mEvent.mHasAltitude = location.hasAltitude();
mEvent.mAltitude = location.getAltitude();
mEvent.mCoordinates = MapUtils.WGS84toETRSTM35FIN(location.getLatitude(), location.getLongitude());
mEvent.mLocationSource = GameHarvest.LOCATION_SOURCE_GPS;
updateLocationOnMap();
updateSubmitButton();
}
}
示例9: betterLocation
import android.location.Location; //导入方法依赖的package包/类
/**
* Determines whether one Location reading is better
*
* @param location1 The new Location that you want to evaluate
* @param location2 The last location fix, to which you want to compare the new one
* @return better location
*/
private Location betterLocation(Location location1, Location location2) {
if (location1 == null && location2 == null) return null;
if (location1 != null && location2 == null) {
return location1;
}
if (location1 == null) {
return location2;
}
long timeDelta = location1.getTime() - location2.getTime();
boolean isSignificantlyNewer = timeDelta > Duration.minutes(10);
boolean isSignificantlyOlder = timeDelta < -Duration.minutes(10);
boolean isNewer = timeDelta > 0;
if (isSignificantlyNewer) {
return location1;
} else if (isSignificantlyOlder) {
return location2;
}
if (location1.getAccuracy() < location2.getAccuracy()) {
return location1;
} else {
return location2;
}
}
示例10: getLastBestLocation
import android.location.Location; //导入方法依赖的package包/类
/**
* Returns the most accurate and timely previously detected location. Where
* the last result is beyond the specified maximum distance or latency a
* one-off location update is returned via the {@link LocationListener}
*
* @param minDistance
* - meter Minimum distance before we require a location update.
* @param latestTime
* - minisecond the lastest time required between location
* updates.
* @return The most accurate and / or timely previously detected location.
*/
public static Location getLastBestLocation(Application application, int minDistance, long latestTime) {
LocationManager locationManager = (LocationManager) application
.getSystemService(Context.LOCATION_SERVICE);
Location bestResult = null;
float bestAccuracy = Float.MAX_VALUE;
long bestTime = Long.MIN_VALUE;
// Iterate through all the providers on the system, keeping
// note of the most accurate result within the acceptable time limit.
// If no result is found within maxTime, return the newest Location.
List<String> matchingProviders = locationManager.getAllProviders();
for (String provider : matchingProviders) {
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
float accuracy = location.getAccuracy();
long time = location.getTime();
if ((time > latestTime && accuracy < bestAccuracy)) {
bestResult = location;
bestAccuracy = accuracy;
bestTime = time;
} else if (time < latestTime && bestAccuracy == Float.MAX_VALUE
&& time > bestTime) {
bestResult = location;
bestTime = time;
}
}
}
return bestResult;
}
示例11: 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();
}
示例12: 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;
}
示例13: Kalman
import android.location.Location; //导入方法依赖的package包/类
/**
*
* @param location
*/
public Kalman(Location location, double coordinateNoise) {
final double accuracy = location.getAccuracy();
final double coordinateNoiseDegrees = coordinateNoise * BackendService.METER_TO_DEG;
double position, noise;
long timeMs = location.getTime();
// Latitude
position = location.getLatitude();
noise = accuracy * BackendService.METER_TO_DEG;
mLatTracker = new Kalman1Dim(coordinateNoiseDegrees, timeMs);
mLatTracker.setState(position, 0.0, noise);
// Longitude
position = location.getLongitude();
noise = accuracy * Math.cos(Math.toRadians(location.getLatitude())) * BackendService.METER_TO_DEG;
mLonTracker = new Kalman1Dim(coordinateNoiseDegrees, timeMs);
mLonTracker.setState(position, 0.0, noise);
// Altitude
position = 0.0;
if (location.hasAltitude()) {
position = location.getAltitude();
noise = accuracy;
mAltTracker = new Kalman1Dim(ALTITUDE_NOISE, timeMs);
mAltTracker.setState(position, 0.0, noise);
}
mTimeOfUpdate = timeMs;
samples = 1;
}
示例14: update
import android.location.Location; //导入方法依赖的package包/类
public synchronized void update(Location location) {
if (location == null)
return;
// Reusable
final double accuracy = location.getAccuracy();
double position, noise;
long timeMs = location.getTime();
predict(timeMs);
mTimeOfUpdate = timeMs;
samples++;
// Latitude
position = location.getLatitude();
noise = accuracy * BackendService.METER_TO_DEG;
mLatTracker.update(position, noise);
// Longitude
position = location.getLongitude();
noise = accuracy * Math.cos(Math.toRadians(location.getLatitude())) * BackendService.METER_TO_DEG ;
mLonTracker.update(position, noise);
// Altitude
if (location.hasAltitude()) {
position = location.getAltitude();
noise = accuracy;
if (mAltTracker == null) {
mAltTracker = new Kalman1Dim(ALTITUDE_NOISE, timeMs);
mAltTracker.setState(position, 0.0, noise);
} else {
mAltTracker.update(position, noise);
}
}
}
示例15: getStatusResource
import android.location.Location; //导入方法依赖的package包/类
@Override
public int getStatusResource() {
if (infoCollector != null) {
final Location loc = infoCollector.getLocationInfo();
if (loc != null) {
if (loc.getAccuracy() <= AppConstants.LOOP_MODE_GPS_ACCURACY_CRITERIA) {
return R.drawable.ic_action_location_found;
}
return R.drawable.ic_action_location_found_network;
}
}
return R.drawable.ic_action_location_no_permission;
}