本文整理匯總了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;
}