當前位置: 首頁>>代碼示例>>Java>>正文


Java Location.getElapsedRealtimeNanos方法代碼示例

本文整理匯總了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;
}
 
開發者ID:gvinciguerra,項目名稱:custode,代碼行數:22,代碼來源:LocationService.java

示例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);
        }
    }
}
 
開發者ID:bfabiszewski,項目名稱:ulogger-android,代碼行數:21,代碼來源:LoggerService.java

示例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;
    }
}
 
開發者ID:rtr-nettest,項目名稱:open-rmbt,代碼行數:15,代碼來源:Helperfunctions.java


注:本文中的android.location.Location.getElapsedRealtimeNanos方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。