当前位置: 首页>>代码示例>>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;未经允许,请勿转载。