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


Java LocationManager.getAllProviders方法代碼示例

本文整理匯總了Java中android.location.LocationManager.getAllProviders方法的典型用法代碼示例。如果您正苦於以下問題:Java LocationManager.getAllProviders方法的具體用法?Java LocationManager.getAllProviders怎麽用?Java LocationManager.getAllProviders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.location.LocationManager的用法示例。


在下文中一共展示了LocationManager.getAllProviders方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getBestLastKnownLocation

import android.location.LocationManager; //導入方法依賴的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: onCreate

import android.location.LocationManager; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    List<String> providers = mgr.getAllProviders();

    //apenas habilitados
    //providers = mgr.getProviders(true);

    adapter=new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, providers);
    setListAdapter(adapter);
}
 
開發者ID:if710,項目名稱:2017.2-codigo,代碼行數:14,代碼來源:ProvidersActivity.java

示例3: getLastBestLocation

import android.location.LocationManager; //導入方法依賴的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;
}
 
開發者ID:Ericliu001,項目名稱:RosterManager,代碼行數:46,代碼來源:LastLocationFinder.java


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