本文整理汇总了Java中android.location.Location.getTime方法的典型用法代码示例。如果您正苦于以下问题:Java Location.getTime方法的具体用法?Java Location.getTime怎么用?Java Location.getTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Location
的用法示例。
在下文中一共展示了Location.getTime方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createLocationListBeforeEvent
import android.location.Location; //导入方法依赖的package包/类
@NonNull
private List<Location> createLocationListBeforeEvent(Date eventDate) {
Location[] locations = locationBuffer.toArray(new Location[locationBuffer.size()]);
// Create current list of dates
List<Location> currentLocationList = Arrays.asList(locations);
// Setup list for dates before the event
List<Location> locationsBeforeEvent = new ArrayList<>();
// Add any events before the event date
for (Location location : currentLocationList) {
Date locationDate = new Date(location.getTime());
if (locationDate.before(eventDate)) {
locationsBeforeEvent.add(location);
}
}
return locationsBeforeEvent;
}
示例2: getActual
import android.location.Location; //导入方法依赖的package包/类
public Location getActual() {
updateLastLocation();
Location bestLocation = getBestLocation();
Location result;
if (mLastLocation != null && bestLocation != null) {
if ((mLastLocation.getTime() - bestLocation.getTime()) > (60 * 60 * 1000)) {
result = mLastLocation;
L.i("return lastLocation");
} else {
result = bestLocation;
L.i("return best location");
}
} else {
result = bestLocation == null ? mLastLocation : bestLocation;
L.i(bestLocation == null ? "return lastLocation, because best is null" :
"return bestLocation, because last is null");
}
return result;
}
示例3: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
public void onLocationChanged(final Location location) {
if (location != null) {
// enable fake speed for tests:
if (BuildConfig.FAKE) {
location.setSpeed(20);
}
lastLocation = location;
sendGpsMapEvent(location);
timestamp = location.getTime();
accuracy = (int) location.getAccuracy();
Log.d(TAG, "onLocationChanged location: lat="
+ location.getLatitude() + ", lon=" + location.getLongitude()
+ ", accuracy: " + accuracy + ", state: " + getState().name());
checkInterval(location);
}
}
示例4: 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();
}
示例5: LandingDetected
import android.location.Location; //导入方法依赖的package包/类
public void LandingDetected(Location l) {
// 3 things to do:
// a) update flight end
if (m_leNewFlight == null) {
Log.e(MFBConstants.LOG_TAG, "logbookentry is NULL in LandingDetected ");
return;
}
// ignore any new landings after engine stop.
if (!m_leNewFlight.FlightInProgress())
return;
m_leNewFlight.dtFlightEnd = new Date(l.getTime());
// b) increment the number of landings
m_leNewFlight.cLandings++;
// and append the nearest route
appendNearest(l);
Log.w(MFBConstants.LOG_TAG, String.format("Landing received, now %d", m_leNewFlight.cLandings));
SaveInProgressFlight();
}
示例6: getCurrentPosition
import android.location.Location; //导入方法依赖的package包/类
/**
* Get the current position. This can return almost immediately if the location is cached or
* request an update, which might take a while.
*
* @param options map containing optional arguments: timeout (millis), maximumAge (millis) and
* highAccuracy (boolean)
*/
@ReactMethod
public void getCurrentPosition(
ReadableMap options,
final Callback success,
Callback error) {
LocationOptions locationOptions = LocationOptions.fromReactMap(options);
try {
LocationManager locationManager =
(LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE);
String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
if (provider == null) {
error.invoke(PositionError.buildError(
PositionError.PERMISSION_DENIED,
"No location provider available."));
return;
}
Location location = locationManager.getLastKnownLocation(provider);
if (location != null &&
SystemClock.currentTimeMillis() - location.getTime() < locationOptions.maximumAge) {
success.invoke(locationToMap(location));
return;
}
new SingleUpdateRequest(locationManager, provider, locationOptions.timeout, success, error)
.invoke();
} catch (SecurityException e) {
throwLocationPermissionMissing(e);
}
}
示例7: 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;
}
示例8: getCurrentPosition
import android.location.Location; //导入方法依赖的package包/类
/**
* Get the current position. This can return almost immediately if the location is cached or
* request an update, which might take a while.
*
* @param options map containing optional arguments: timeout (millis), maximumAge (millis) and
* highAccuracy (boolean)
*/
@ReactMethod
public void getCurrentPosition(
ReadableMap options,
final Callback success,
Callback error) {
LocationOptions locationOptions = LocationOptions.fromReactMap(options);
try {
LocationManager locationManager =
(LocationManager) getReactApplicationContext().getSystemService(Context.LOCATION_SERVICE);
String provider = getValidProvider(locationManager, locationOptions.highAccuracy);
if (provider == null) {
emitError(PositionError.PERMISSION_DENIED, "No location provider available.");
return;
}
Location location = locationManager.getLastKnownLocation(provider);
if (location != null &&
SystemClock.currentTimeMillis() - location.getTime() < locationOptions.maximumAge) {
success.invoke(locationToMap(location));
return;
}
new SingleUpdateRequest(locationManager, provider, locationOptions.timeout, success, error)
.invoke();
} catch (SecurityException e) {
throwLocationPermissionMissing(e);
}
}
示例9: onResume
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onResume() {
if ( this.locationManager != null && this.locationListener != null ) {
// 各プロバイダーが利用可能かどうかをチェックする。
this.gpsProviderEnabled = this.locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER );
this.networkProviderEnabled = this.locationManager.isProviderEnabled( LocationManager.NETWORK_PROVIDER );
// GPSプロバイダーが有効な場合の処理。
if ( this.gpsProviderEnabled ) {
final Location lastKnownGPSLocation = this.locationManager.getLastKnownLocation( LocationManager.GPS_PROVIDER );
if ( lastKnownGPSLocation != null && lastKnownGPSLocation.getTime() > System.currentTimeMillis() - LOCATION_OUTDATED_WHEN_OLDER_MS ) {
locationListener.onLocationChanged( lastKnownGPSLocation );
}
if (locationManager.getProvider(LocationManager.GPS_PROVIDER)!=null) {
this.locationManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, LOCATION_UPDATE_MIN_TIME_GPS, LOCATION_UPDATE_DISTANCE_GPS, this.locationListener );
Log.d("ProviderName", "gps");
}
}
// ネットワーク/WiFi位置情報(ネットワーク基地局)プロバイダーが有効な場合の処理。
if ( this.networkProviderEnabled ) {
final Location lastKnownNWLocation = this.locationManager.getLastKnownLocation( LocationManager.NETWORK_PROVIDER );
if ( lastKnownNWLocation != null && lastKnownNWLocation.getTime() > System.currentTimeMillis() - LOCATION_OUTDATED_WHEN_OLDER_MS ) {
locationListener.onLocationChanged( lastKnownNWLocation );
}
if (locationManager.getProvider(LocationManager.NETWORK_PROVIDER)!=null) {
this.locationManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, LOCATION_UPDATE_MIN_TIME_NW, LOCATION_UPDATE_DISTANCE_NW, this.locationListener );
Log.d("ProviderName", "network");
}
}
// ユーザーにより、位置情報が有効になっていない場合の処理。オススメ: このイベントはアプリで処理してください。例えば「new Intent( Settings.ACTION_LOCATION_SOURCE_SETTINGS )」というコードで、ユーザーを直接ロケーションに誘導するなど。
if ( !this.gpsProviderEnabled || !this.networkProviderEnabled ) {
Toast.makeText( this.context, "[設定]-[位置情報]で[高精度]/[バッテリー節約]などを選択してGPSおよびモバイルネットワークの両方を有効にしてください。", Toast.LENGTH_LONG ).show();
}
}
}
示例10: 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();
}
示例11: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
public void onLocationChanged(Location location) {
mGeomagneticField = new GeomagneticField((float) location.getLatitude(),
(float) location.getLongitude(), (float) location.getAltitude(),
location.getTime());
currentLocation = mProj.LL2TM2(location.getLongitude(), location.getLatitude());
mTvGps.setText(String.format(Locale.CHINESE, "== GPS資訊 ==\n經度=%s\n緯度=%s\n橢球高=%.2f公尺\n速度=%.2f公尺/秒\n航向:%s\nTM2 E %.2f公尺, N %.2f公尺",
Tools.Deg2DmsStr2(location.getLongitude()),
Tools.Deg2DmsStr2(location.getLatitude()),
location.getAltitude(),
location.getSpeed(),
Tools.ang2Str(location.getBearing()),
currentLocation[0], currentLocation[1]));
double dx = currentLocation[0] - lastX;
double dy = currentLocation[1] - lastY;
if (Math.sqrt(dx*dx + dy*dy) > 1) {
lastX = currentLocation[0]/10; lastX *= 10;
lastY = currentLocation[1]/10; lastY *= 10;
List<CPDB.CP> cps = cpdb.getCp(lastX, lastY, 0);
if (cps.size() > 0) {
String cpMsg = "鄰近控制點:\n";
int i=0;
for (CPDB.CP cp : cps) {
double dx1 = cp.x - currentLocation[0], dy1 = cp.y-currentLocation[1];
double[] resCP = Tools.POLd(dy1, dx1);
cpMsg += String.format(Locale.CHINESE, "%s %[email protected]%d%s\n距離=%.0f公尺\n方位=%s\n",
cp.number, (++i), cp.t, (cp.name.length()>0?"("+cp.name+")":""),
resCP[0], Tools.Deg2DmsStr2(resCP[1])
);
}
mTvControllPoint.setText(cpMsg);
}
}
}
示例12: 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;
}
示例13: 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);
}
}
}
示例14: getAge
import android.location.Location; //导入方法依赖的package包/类
/**
* @param loc location object
* @return age of event in ns
*/
public static Long getAge(Location loc) {
if (loc == null) {
return null;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
return SystemClock.elapsedRealtimeNanos() - loc.getElapsedRealtimeNanos();
} else {
return (System.currentTimeMillis() - loc.getTime()) * 1000000L;
}
}
示例15: TakeoffDetected
import android.location.Location; //导入方法依赖的package包/类
public void TakeoffDetected(Location l, Boolean fIsNight) {
if (m_leNewFlight == null) {
Log.e(MFBConstants.LOG_TAG, "logbookentry is NULL in TakeoffDetected");
return;
}
// ignore any new takeoffs after engine stop or before engine start
if (!m_leNewFlight.FlightInProgress())
return;
boolean fNeedsViewRefresh = false;
// create or increment a night-takeoff property.
if (fIsNight) {
m_leNewFlight.AddNightTakeoff();
fNeedsViewRefresh = true;
}
if (m_delegate != null)
m_delegate.unPauseFlight(); // don't pause in flight
if (!m_leNewFlight.isKnownFlightStart()) {
if (m_delegate != null)
m_delegate.FromView();
m_leNewFlight.dtFlightStart = new Date(l.getTime());
appendNearest(l);
fNeedsViewRefresh = true;
}
if (fNeedsViewRefresh && m_delegate != null)
m_delegate.RefreshDetectedFields();
}