本文整理汇总了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;
}
示例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);
}
示例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;
}