use of android.location.Location in project robolectric by robolectric.
the class ShadowLocationManager method copyOf.
private Location copyOf(Location location) {
if (location == null)
return null;
Location copy = new Location(location);
copy.setAccuracy(location.getAccuracy());
copy.setAltitude(location.getAltitude());
copy.setBearing(location.getBearing());
copy.setExtras(location.getExtras());
copy.setLatitude(location.getLatitude());
copy.setLongitude(location.getLongitude());
copy.setProvider(location.getProvider());
copy.setSpeed(location.getSpeed());
copy.setTime(location.getTime());
return copy;
}
use of android.location.Location in project Android-FusedLocation by levelup.
the class FusedCriteriaTest method testDefaultCriteria.
public void testDefaultCriteria() throws InterruptedException {
final CountDownLatch signal = new CountDownLatch(1);
Criteria criteria = new Criteria();
locationManager.requestLocationUpdates(MIN_TIME_IN_MS, MIN_DISTANCE_IN_M, criteria, new LocationListener() {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onLocationChanged(Location location) {
assertNotNull(location);
signal.countDown();
}
}, null);
signal.await(MIN_TIME_IN_MS, TimeUnit.MILLISECONDS);
}
use of android.location.Location in project coursera-android by aporter.
the class LocationGetLocationActivity method bestLastKnownLocation.
// Get the last known location from all providers
// return best reading that is as accurate as minAccuracy and
// was taken no longer then minAge milliseconds ago. If none,
// return null.
private Location bestLastKnownLocation(float minAccuracy, long maxAge) {
Location bestResult = null;
float bestAccuracy = Float.MAX_VALUE;
long bestAge = Long.MIN_VALUE;
List<String> matchingProviders = mLocationManager.getAllProviders();
for (String provider : matchingProviders) {
Location location = mLocationManager.getLastKnownLocation(provider);
if (location != null) {
float accuracy = location.getAccuracy();
long time = location.getTime();
if (accuracy < bestAccuracy) {
bestResult = location;
bestAccuracy = accuracy;
bestAge = time;
}
}
}
// Return best reading or null
if (bestAccuracy > minAccuracy || (System.currentTimeMillis() - bestAge) > maxAge) {
return null;
} else {
return bestResult;
}
}
use of android.location.Location in project facebook-android-sdk by facebook.
the class PlacePickerFragment method setSettingsFromBundle.
@Override
public void setSettingsFromBundle(Bundle inState) {
super.setSettingsFromBundle(inState);
if (inState != null) {
setRadiusInMeters(inState.getInt(RADIUS_IN_METERS_BUNDLE_KEY, radiusInMeters));
setResultsLimit(inState.getInt(RESULTS_LIMIT_BUNDLE_KEY, resultsLimit));
if (inState.containsKey(SEARCH_TEXT_BUNDLE_KEY)) {
setSearchText(inState.getString(SEARCH_TEXT_BUNDLE_KEY));
}
if (inState.containsKey(LOCATION_BUNDLE_KEY)) {
Location location = inState.getParcelable(LOCATION_BUNDLE_KEY);
setLocation(location);
}
showSearchBox = inState.getBoolean(SHOW_SEARCH_BOX_BUNDLE_KEY, showSearchBox);
}
}
use of android.location.Location in project AndroidSDK-RecipeBook by gabu.
the class Recipe073 method onResume.
@Override
protected void onResume() {
super.onResume();
// 現在の状況に最適なプロバイダを取得します。
// Criteriaで細かい条件が指定できますが今回はデフォルトで
String provider;
provider = mManager.getBestProvider(new Criteria(), true);
if (provider == null) {
// 位置情報が取得できるプロバイダがありません。
// Wifiにも3Gにも繋がっていないなど。
}
mManager.requestLocationUpdates(provider, 0, 0, this);
// 最後に取得した位置情報を取得
Location location = mManager.getLastKnownLocation(provider);
if (location != null)
onLocationChanged(location);
}
Aggregations