本文整理汇总了Java中android.location.Location.distanceTo方法的典型用法代码示例。如果您正苦于以下问题:Java Location.distanceTo方法的具体用法?Java Location.distanceTo怎么用?Java Location.distanceTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Location
的用法示例。
在下文中一共展示了Location.distanceTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMaxDistance
import android.location.Location; //导入方法依赖的package包/类
public double getMaxDistance() {
if (maxDistance == 0) {
for (Gateway gateway : gateways) {
double distance = 0;
if (gateway.getLatitude() == 0 || gateway.getLongitude() == 0 || latitude == 0 || longitude == 0) {
distance = 0;
} else {
Location locationA = new Location("");
locationA.setLatitude(gateway.getLatitude());
locationA.setLongitude(gateway.getLongitude());
Location locationB = new Location("");
locationB.setLatitude(latitude);
locationB.setLongitude(longitude);
distance = locationA.distanceTo(locationB);
}
if (distance > maxDistance) {
maxDistance = distance;
}
}
}
return maxDistance;
}
示例2: isLocationPlausible
import android.location.Location; //导入方法依赖的package包/类
private boolean isLocationPlausible(@Nullable Location location) {
if (location == null) return false;
// isFromMockProvider may give wrong response for some applications
// Warning: With rooted devices we cannot ensure that the location is not mocked
boolean mocked = isMocked(location);
if (mocked) mLastMockLocation = location;
boolean permittedMock = !mocked || isMockLocationsEnabled();
boolean permitted = permittedMock
&& (mLastLocation == null || location.getAccuracy() < ACCURACY_THRESHOLD);
if (mLastMockLocation == null) return permitted;
if (location.distanceTo(mLastMockLocation) > KM) {
mLastMockLocation = null;
return permitted;
}
return false;
}
示例3: 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;
}
示例4: autoCenterMap
import android.location.Location; //导入方法依赖的package包/类
void autoCenterMap() {
/*
autocentre the map if:
the setting is on,
and we moved more than 10 meters
or we have not centreed the map at our location
*/
if (mMap == null) {
//prevent null pointer exceptions
return;
}
SharedPreferences myPrefs = getSharedPreferences(SettingConstants.PREFERENCES, MODE_PRIVATE);
if (myPrefs.getBoolean(SettingConstants.AUTO_CENTER, SettingConstants.AUTO_CENTER_DEFAULT)) {
Location mapCentreLocation = new Location("");
mapCentreLocation.setLatitude(mMap.getCameraPosition().target.latitude);
mapCentreLocation.setLongitude(mMap.getCameraPosition().target.longitude);
MyApplication mApplication = (MyApplication) getApplicationContext();
if (mApplication.getLatestLon() != 0 && mApplication.getLatestLat() != 0) {
Location currentLocation = new Location("");
currentLocation.setLatitude(mApplication.getLatestLat());
currentLocation.setLongitude(mApplication.getLatestLon());
if (currentLocation.distanceTo(mapCentreLocation) > 10) {
mMap.animateCamera(CameraUpdateFactory.newLatLng(new LatLng(mApplication.getLatestLat(), mApplication.getLatestLon())));
}
}
}
if (myPrefs.getBoolean(SettingConstants.AUTO_ZOOM, SettingConstants.AUTO_CENTER_DEFAULT)) {
autoZoomMap();
}
}
示例5: calcDistance
import android.location.Location; //导入方法依赖的package包/类
/**
* Receives as input the coordinates of a station and returns it's distance to the user
*/
private float calcDistance(float latitude, float longitude) {
Location cli_loc = new Location("Client");
Location station_loc = new Location("Station");
cli_loc.setLongitude(userLong);
cli_loc.setLatitude(userLat);
station_loc.setLatitude(latitude);
station_loc.setLongitude(longitude);
return cli_loc.distanceTo(station_loc);
}
示例6: getDistance
import android.location.Location; //导入方法依赖的package包/类
public static float getDistance(Location loc1, Location loc2) {
return loc1.distanceTo(loc2);
}
示例7: getDistanceFromCurrentLocation
import android.location.Location; //导入方法依赖的package包/类
/** @return distance in meters between the current geolocated position and this marker. */
@Nullable
public Float getDistanceFromCurrentLocation() {
Location currentLocation = CivifyMap.getInstance().getCurrentLocation();
if (currentLocation != null) {
return currentLocation.distanceTo(LocationAdapter.getLocation(getPosition()));
}
return null;
}
示例8: distance
import android.location.Location; //导入方法依赖的package包/类
public static double distance(LatLng pos1, LatLng pos2) {
Location loc1 = new Location("");
loc1.setLatitude(pos1.latitude);
loc1.setLongitude(pos1.longitude);
Location loc2 = new Location("");
loc2.setLatitude(pos2.latitude);
loc2.setLongitude(pos2.longitude);
double distanceInKm = loc1.distanceTo(loc2) * 0.001;
return distanceInKm;
}
示例9: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onLocationChanged(Location curLocation)
{
if (lastTestLocation != null)
{
final float distance = curLocation.distanceTo(lastTestLocation);
loopModeResults.setLastDistance(distance);
loopModeResults.setLocationProvider(curLocation.getProvider());
loopModeResults.setLastAccuracy(curLocation.getAccuracy());
Log.d(TAG, "location distance: " + distance + "; maxMovement: " + loopModeResults.getMaxMovement());
onAlarmOrLocation(false);
}
lastLocation = curLocation;
}
示例10: 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);
}
示例11: drawXMetric
import android.location.Location; //导入方法依赖的package包/类
private void drawXMetric(Canvas canvas, Paint textPaint, Paint barPaint) {
Projection projection = mMap.getProjection();
if (projection != null) {
LatLng p1 = projection.fromScreenLocation(new Point((int) ((getWidth() / 2) - (mXdpi / 2)), getHeight() / 2));
LatLng p2 = projection.fromScreenLocation(new Point((int) ((getWidth() / 2) + (mXdpi / 2)), getHeight() / 2));
Location locationP1 = new Location("ScaleBar location p1");
Location locationP2 = new Location("ScaleBar location p2");
locationP1.setLatitude(p1.latitude);
locationP2.setLatitude(p2.latitude);
locationP1.setLongitude(p1.longitude);
locationP2.setLongitude(p2.longitude);
float xMetersPerInch = locationP1.distanceTo(locationP2);
if (mIsLatitudeBar) {
String xMsg = scaleBarLengthText(xMetersPerInch);
Rect xTextRect = new Rect();
textPaint.getTextBounds(xMsg, 0, xMsg.length(), xTextRect);
int textSpacing = (int) (xTextRect.height() / 5.0);
canvas.drawRect(mXOffset, mYOffset, mXOffset + mXdpi, mYOffset + mLineWidth, barPaint);
canvas.drawRect(mXOffset + mXdpi, mYOffset, mXOffset + mXdpi + mLineWidth, mYOffset +
xTextRect.height() + mLineWidth + textSpacing, barPaint);
if (!mIsLongitudeBar) {
canvas.drawRect(mXOffset, mYOffset, mXOffset + mLineWidth, mYOffset +
xTextRect.height() + mLineWidth + textSpacing, barPaint);
}
canvas.drawText(xMsg, (mXOffset + mXdpi / 2 - xTextRect.width() / 2),
(mYOffset + xTextRect.height() + mLineWidth + textSpacing), textPaint);
}
}
}
示例12: distance
import android.location.Location; //导入方法依赖的package包/类
public static float distance(LatLng start, LatLng end) {
Location loc1 = new Location("");
loc1.setLatitude(start.latitude);
loc1.setLongitude(start.longitude);
Location loc2 = new Location("");
loc2.setLatitude(end.latitude);
loc2.setLongitude(end.longitude);
return loc1.distanceTo(loc2);
}
示例13: locationIsAtStatus
import android.location.Location; //导入方法依赖的package包/类
/**
* Determines if the current location is approximately the same as the location
* for a particular status. Used to check if we'll add a new status, or
* update the most recent status of we're stationary.
*/
private boolean locationIsAtStatus(Location location, int statusIndex) {
if (mTransportStatuses.size() <= statusIndex) {
return false;
}
Map<String, Object> status = mTransportStatuses.get(statusIndex);
Location locationForStatus = new Location("");
locationForStatus.setLatitude((double) status.get("lat"));
locationForStatus.setLongitude((double) status.get("lng"));
float distance = location.distanceTo(locationForStatus);
double la=(double) status.get("lat");
double lo=(double) status.get("lng");
Log.d(TAG, String.format("Distance from status %s is %sm %s %s", statusIndex, distance,la,lo));
return distance < mFirebaseRemoteConfig.getLong("LOCATION_MIN_DISTANCE_CHANGED");
}
示例14: VisitedAirportsForUser
import android.location.Location; //导入方法依赖的package包/类
public VisitedAirport[] VisitedAirportsForUser(String szAuthToken, Context c) {
SoapObject Request = setMethod("VisitedAirports");
Request.addProperty("szAuthToken", szAuthToken);
VisitedAirport[] rgva = new VisitedAirport[0];
SoapObject result = (SoapObject) Invoke(c);
if (result == null)
setLastError("Error retrieving visited airports - " + getLastError());
else {
Location l = MFBLocation.LastSeenLoc();
try {
rgva = new VisitedAirport[result.getPropertyCount()];
for (int i = 0; i < rgva.length; i++) {
rgva[i] = new VisitedAirport((SoapObject) result.getProperty(i));
if (l != null)
rgva[i].airport.Distance = l.distanceTo(rgva[i].airport.getLocation()) * MFBConstants.METERS_TO_NM;
}
} catch (Exception e) {
setLastError(getLastError() + e.getMessage());
}
}
return rgva;
}
示例15: allowMeasurement
import android.location.Location; //导入方法依赖的package包/类
@Override
public boolean allowMeasurement() {
if (checkLocationPermission()) {
//get the last good current location
Location locationNow = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER);
//check the distance between this location, and the user provided one
float distanceNow = locationNow.distanceTo(locationNear);
//if within distance, then allow measurement
if (distanceNow <= distanceLimit)
return true;
}
return false;
}