本文整理汇总了Java中android.location.Location.getElapsedRealtimeNanos方法的典型用法代码示例。如果您正苦于以下问题:Java Location.getElapsedRealtimeNanos方法的具体用法?Java Location.getElapsedRealtimeNanos怎么用?Java Location.getElapsedRealtimeNanos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.location.Location
的用法示例。
在下文中一共展示了Location.getElapsedRealtimeNanos方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: onLocationChanged
import android.location.Location; //导入方法依赖的package包/类
@Override
public void onLocationChanged(Location loc) {
if (Logger.DEBUG) { Log.d(TAG, "[location changed: " + loc + "]"); }
if (!skipLocation(loc)) {
lastLocation = loc;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
lastUpdateRealtime = SystemClock.elapsedRealtime();
} else {
lastUpdateRealtime = loc.getElapsedRealtimeNanos() / 1000000;
}
db.writeLocation(loc);
sendBroadcast(BROADCAST_LOCATION_UPDATED);
if (liveSync) {
startService(syncIntent);
}
}
}
示例3: 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;
}
}