List of usage examples for android.location Criteria setPowerRequirement
public void setPowerRequirement(int level)
From source file:Main.java
public static String getBestProvider(LocationManager locationManager) throws IllegalArgumentException { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.NO_REQUIREMENT); return locationManager.getBestProvider(criteria, true); }
From source file:com.appdynamics.demo.gasp.utils.LocationServices.java
/** * Set Location Services and get current location *//*from w w w .ja v a2 s .c o m*/ public static Location getLocation(Context context) { Location location = null; try { String svcName = Context.LOCATION_SERVICE; LocationManager locationManager = (LocationManager) context.getSystemService(svcName); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(false); criteria.setCostAllowed(true); String provider = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(provider); Log.i(TAG, "Current Latitude = " + location.getLatitude()); Log.i(TAG, "Current Longitude = " + location.getLongitude()); } catch (Exception e) { e.printStackTrace(); } return location; }
From source file:ru.dublgis.androidlocation.PassiveLocationProvider.java
static public boolean requestSingleUpdate(PendingIntent intent) { try {/*from w w w . ja va2 s. c om*/ if (null != mContext && null != mLocationManager && isPermissionGranted(mContext)) { Criteria criteria = new Criteria(); criteria.setPowerRequirement(Criteria.POWER_HIGH); mLocationManager.requestSingleUpdate(criteria, intent); return true; } } catch (Throwable e) { Log.e(TAG, "Failed to start location updates", e); } return false; }
From source file:Main.java
/** * this criteria will settle for less accuracy, high power, and cost *//* w w w . j ava 2 s . co m*/ public static Criteria createCoarseCriteria() { Criteria c = new Criteria(); c.setAccuracy(Criteria.ACCURACY_COARSE); c.setAltitudeRequired(false); c.setBearingRequired(false); c.setSpeedRequired(false); c.setCostAllowed(true); c.setPowerRequirement(Criteria.POWER_HIGH); return c; }
From source file:Main.java
public static String getBestProvider(LocationManager locationmanager) { String s = null;// ww w . jav a 2 s . c om if (locationmanager != null) { Criteria criteria = new Criteria(); criteria.setAccuracy(2); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(0); s = locationmanager.getBestProvider(criteria, true); if (s == null) s = "network"; } return s; }
From source file:com.airbop.library.simple.CommonUtilities.java
/** * Simple helper that gets the location criteria that we want. * @return//from www . j a v a 2s. c o m */ public static Criteria getCriteria() { if (true) { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(false); criteria.setCostAllowed(true); return criteria; } return null; }
From source file:com.ushahidi.android.app.util.Util.java
/** this criteria needs high accuracy, high power, and cost */ public static Criteria createFineCriteria() { Criteria c = new Criteria(); c.setAccuracy(Criteria.ACCURACY_FINE); c.setAltitudeRequired(false);/* w w w. j av a 2 s .com*/ c.setBearingRequired(false); c.setSpeedRequired(false); c.setCostAllowed(true); c.setPowerRequirement(Criteria.POWER_HIGH); return c; }
From source file:net.frakbot.FWeather.util.LocationHelper.java
/** * Returns the default criteria set for the LocationManager. * @return the default Criteria//from w w w.j ava2 s . c o m */ private static Criteria getDefaultCriteria() { Criteria criteria = new Criteria(); criteria.setCostAllowed(false); criteria.setHorizontalAccuracy(Criteria.ACCURACY_LOW); criteria.setVerticalAccuracy(Criteria.NO_REQUIREMENT); criteria.setSpeedRequired(false); criteria.setPowerRequirement(Criteria.POWER_LOW); return criteria; }
From source file:com.cloudbees.gasp.activity.GaspLocationsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_locations); GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); LocationManager locationManager;/*from w w w . java 2s . c o m*/ String svcName = Context.LOCATION_SERVICE; locationManager = (LocationManager) getSystemService(svcName); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(false); criteria.setCostAllowed(true); String provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); Log.i(TAG, "CURRENT LOCATION"); Log.i(TAG, "Latitude = " + location.getLatitude()); Log.i(TAG, "Longitude = " + location.getLongitude()); if (location != null) { double latitude = location.getLatitude(); double longitude = location.getLongitude(); Geocoder gc = new Geocoder(this, Locale.getDefault()); if (!Geocoder.isPresent()) Log.i(TAG, "No geocoder available"); else { try { List<Address> addresses = gc.getFromLocation(latitude, longitude, 1); StringBuilder sb = new StringBuilder(); if (addresses.size() > 0) { Address address = addresses.get(0); for (int i = 0; i < address.getMaxAddressLineIndex(); i++) sb.append(address.getAddressLine(i)).append(" "); sb.append(address.getLocality()).append(""); sb.append(address.getPostalCode()).append(" "); sb.append(address.getCountryName()); } Log.i(TAG, "Address: " + sb.toString()); } catch (IOException e) { Log.d(TAG, "IOException getting address from geocoder", e); } } } map.setMyLocationEnabled(true); LatLng myLocation = new LatLng(location.getLatitude(), location.getLongitude()); CameraPosition cameraPosition = new CameraPosition.Builder().target(myLocation).zoom(16).bearing(0).tilt(0) .build(); map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); new LocationMapper().execute(); }
From source file:net.quranquiz.ui.QQMap.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map);//from w ww . ja va2 s . c om map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); map.setOnMarkerClickListener((OnMarkerClickListener) this); cairo = new LatLng(30.1, 31.45); LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabledGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER); // Check if enabled and if not send user to the GSP settings // Better solution would be to display a dialog and suggesting to // go to the settings if (!enabledGPS) { Toast.makeText(this, "GPS signal not found", Toast.LENGTH_LONG).show(); startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { Toast.makeText(this, "Selected Provider " + provider, Toast.LENGTH_SHORT).show(); meMarker = map.addMarker( new MarkerOptions().position(cairo).title("That's Me").snippet("a normal QuranQuiz Node!") .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))); map.moveCamera(CameraUpdateFactory.newLatLngZoom(cairo, 12.0f)); onLocationChanged(location); } else { //do something } }