android.location.Criteria Java Examples
The following examples show how to use
android.location.Criteria.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GPSTracker.java From AsteroidOSSync with GNU General Public License v3.0 | 6 votes |
public void updateLocation() { try { mLocationManager = (LocationManager) mContext .getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_LOW); criteria.setSpeedRequired(false); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); String provider = mLocationManager.getBestProvider(criteria, true); if(provider != null) { mLocationManager.requestSingleUpdate(provider, this, null); mCanGetLocation = true; } } catch (SecurityException | NullPointerException e) { e.printStackTrace(); } }
Example #2
Source File: LocationManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Return the name of the best provider given a Criteria object. * This method has been deprecated from the public API, * and the whole LocationProvider (including #meetsCriteria) * has been deprecated as well. So this method now uses * some simplified logic. */ @Override public String getBestProvider(Criteria criteria, boolean enabledOnly) { String result = null; List<String> providers = getProviders(criteria, enabledOnly); if (!providers.isEmpty()) { result = pickBest(providers); if (D) Log.d(TAG, "getBestProvider(" + criteria + ", " + enabledOnly + ")=" + result); return result; } providers = getProviders(null, enabledOnly); if (!providers.isEmpty()) { result = pickBest(providers); if (D) Log.d(TAG, "getBestProvider(" + criteria + ", " + enabledOnly + ")=" + result); return result; } if (D) Log.d(TAG, "getBestProvider(" + criteria + ", " + enabledOnly + ")=" + result); return null; }
Example #3
Source File: DistanceFilterLocationProvider.java From background-geolocation-android with Apache License 2.0 | 6 votes |
@Override public void onReceive(Context context, Intent intent) { logger.info("Stationary location monitor fired"); playDebugTone(Tone.DIALTONE); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH); criteria.setPowerRequirement(Criteria.POWER_HIGH); try { locationManager.requestSingleUpdate(criteria, singleUpdatePI); } catch (SecurityException e) { logger.error("Security exception: {}", e.getMessage()); } }
Example #4
Source File: RawLocationProvider.java From background-geolocation-android with Apache License 2.0 | 6 votes |
/** * Translates a number representing desired accuracy of Geolocation system from set [0, 10, 100, 1000]. * 0: most aggressive, most accurate, worst battery drain * 1000: least aggressive, least accurate, best for battery. */ private Integer translateDesiredAccuracy(Integer accuracy) { if (accuracy >= 1000) { return Criteria.ACCURACY_LOW; } if (accuracy >= 100) { return Criteria.ACCURACY_MEDIUM; } if (accuracy >= 10) { return Criteria.ACCURACY_HIGH; } if (accuracy >= 0) { return Criteria.ACCURACY_HIGH; } return Criteria.ACCURACY_MEDIUM; }
Example #5
Source File: RawLocationProvider.java From background-geolocation-android with Apache License 2.0 | 6 votes |
@Override public void onStart() { if (isStarted) { return; } Criteria criteria = new Criteria(); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(true); criteria.setCostAllowed(true); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setHorizontalAccuracy(translateDesiredAccuracy(mConfig.getDesiredAccuracy())); criteria.setPowerRequirement(Criteria.POWER_HIGH); try { locationManager.requestLocationUpdates(locationManager.getBestProvider(criteria, true), mConfig.getInterval(), mConfig.getDistanceFilter(), this); isStarted = true; } catch (SecurityException e) { logger.error("Security exception: {}", e.getMessage()); this.handleSecurityException(e); } }
Example #6
Source File: GoogleMapImpl.java From android_packages_apps_GmsCore with Apache License 2.0 | 6 votes |
private GoogleMapImpl(Context context, GoogleMapOptions options) { this.context = context; Context appContext = context; if (appContext.getApplicationContext() != null) appContext = appContext.getApplicationContext(); Context wrappedContext = ApplicationContextWrapper.gmsContextWithAttachedApplicationContext(appContext); backendMap = new BackendMap(wrappedContext, this); uiSettings = new UiSettingsImpl(this); projection = new ProjectionImpl(backendMap.getViewport()); this.options = options; criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_MEDIUM); if (options != null) initFromOptions(); }
Example #7
Source File: ChronometerView.java From open-quartz with Apache License 2.0 | 6 votes |
public ChronometerView(Context context) { this(context, null, 0); final StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder() .permitAll().build(); StrictMode.setThreadPolicy(policy); locationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); geocoder = new Geocoder(context); criteria = new Criteria(); best = locationManager.getBestProvider(criteria, true); location = locationManager.getLastKnownLocation(best); providers = locationManager.getProviders(criteria, true); for (String provider : providers) { locationManager.requestLocationUpdates(provider, 0, 0, this); Log.e("TAG", "" + provider); } }
Example #8
Source File: Preferences.java From al-muazzin with GNU Lesser General Public License v2.1 | 6 votes |
public Location getCurrentLocation(Context context) { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setCostAllowed(true); LocationManager locationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); try { Location currentLocation = locationManager.getLastKnownLocation(locationManager .getBestProvider(criteria, true)); if (currentLocation == null) { criteria.setAccuracy(Criteria.ACCURACY_COARSE); currentLocation = locationManager.getLastKnownLocation(locationManager .getBestProvider(criteria, true)); } return currentLocation; } catch (IllegalArgumentException iae) { return null; } }
Example #9
Source File: MyLocationActivity.java From Complete-Google-Map-API-Tutorial with Apache License 2.0 | 6 votes |
private void goToMyLocation() { if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { enableMyLocation(); } else { googleMap.setMyLocationEnabled(true); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false)); if (location != null) { googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13)); } } }
Example #10
Source File: LocationUtils.java From DevUtils with Apache License 2.0 | 6 votes |
/** * 获取定位参数对象 * @return {@link Criteria} */ private static Criteria getCriteria() { Criteria criteria = new Criteria(); // 设置定位精确度 Criteria.ACCURACY_COARSE 比较粗略, Criteria.ACCURACY_FINE 则比较精细 criteria.setAccuracy(Criteria.ACCURACY_FINE); // 设置是否要求速度 criteria.setSpeedRequired(false); // 设置是否允许运营商收费 criteria.setCostAllowed(false); // 设置是否需要方位信息 criteria.setBearingRequired(false); // 设置是否需要海拔信息 criteria.setAltitudeRequired(false); // 设置对电源的需求 criteria.setPowerRequirement(Criteria.POWER_LOW); return criteria; }
Example #11
Source File: DistanceFilterLocationProvider.java From background-geolocation-android with Apache License 2.0 | 6 votes |
/** * Translates a number representing desired accuracy of Geolocation system from set [0, 10, 100, 1000]. * 0: most aggressive, most accurate, worst battery drain * 1000: least aggressive, least accurate, best for battery. */ private Integer translateDesiredAccuracy(Integer accuracy) { if (accuracy >= 1000) { return Criteria.ACCURACY_LOW; } if (accuracy >= 100) { return Criteria.ACCURACY_MEDIUM; } if (accuracy >= 10) { return Criteria.ACCURACY_HIGH; } if (accuracy >= 0) { return Criteria.ACCURACY_HIGH; } return Criteria.ACCURACY_MEDIUM; }
Example #12
Source File: NativeLocationClientImpl.java From android_external_GmsLib with Apache License 2.0 | 6 votes |
private static Criteria makeNativeCriteria(LocationRequest request) { Criteria criteria = new Criteria(); switch (request.getPriority()) { case LocationRequest.PRIORITY_HIGH_ACCURACY: criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); break; case LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY: default: criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_MEDIUM); break; case LocationRequest.PRIORITY_NO_POWER: case LocationRequest.PRIORITY_LOW_POWER: criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); } return criteria; }
Example #13
Source File: LocationUtils.java From Android-UtilCode with Apache License 2.0 | 6 votes |
/** * 设置定位参数 * * @return {@link Criteria} */ private static Criteria getCriteria() { Criteria criteria = new Criteria(); // 设置定位精确度 Criteria.ACCURACY_COARSE比较粗略,Criteria.ACCURACY_FINE则比较精细 criteria.setAccuracy(Criteria.ACCURACY_FINE); // 设置是否要求速度 criteria.setSpeedRequired(false); // 设置是否允许运营商收费 criteria.setCostAllowed(false); // 设置是否需要方位信息 criteria.setBearingRequired(false); // 设置是否需要海拔信息 criteria.setAltitudeRequired(false); // 设置对电源的需求 criteria.setPowerRequirement(Criteria.POWER_LOW); return criteria; }
Example #14
Source File: MedicAndroidJavascript.java From medic-android with GNU Affero General Public License v3.0 | 6 votes |
@Deprecated @org.xwalk.core.JavascriptInterface @android.webkit.JavascriptInterface @SuppressLint("MissingPermission") // handled by catch(Exception) /** * @deprecated Location should be fetched directly from the browser. * @see https://github.com/medic/medic-webapp/issues/3781 */ public String getLocation() { try { if(locationManager == null) return jsonError("LocationManager not set. Cannot retrieve location."); String provider = locationManager.getBestProvider(new Criteria(), true); if(provider == null) return jsonError("No location provider available."); Location loc = locationManager.getLastKnownLocation(provider); if(loc == null) return jsonError("Provider '" + provider + "' did not provide a location."); return new JSONObject() .put("lat", loc.getLatitude()) .put("long", loc.getLongitude()) .toString(); } catch(Exception ex) { return jsonError("Problem fetching location: ", ex); } }
Example #15
Source File: RxLocationTool.java From RxTools-master with Apache License 2.0 | 6 votes |
/** * 设置定位参数 * * @return {@link Criteria} */ private static Criteria getCriteria() { Criteria criteria = new Criteria(); //设置定位精确度 Criteria.ACCURACY_COARSE比较粗略,Criteria.ACCURACY_FINE则比较精细 criteria.setAccuracy(Criteria.ACCURACY_FINE); //设置是否要求速度 criteria.setSpeedRequired(false); // 设置是否允许运营商收费 criteria.setCostAllowed(false); //设置是否需要方位信息 criteria.setBearingRequired(false); //设置是否需要海拔信息 criteria.setAltitudeRequired(false); // 设置对电源的需求 criteria.setPowerRequirement(Criteria.POWER_LOW); return criteria; }
Example #16
Source File: LocationUtils.java From AndroidUtilCode with Apache License 2.0 | 6 votes |
/** * 设置定位参数 * * @return {@link Criteria} */ private static Criteria getCriteria() { Criteria criteria = new Criteria(); // 设置定位精确度 Criteria.ACCURACY_COARSE比较粗略,Criteria.ACCURACY_FINE则比较精细 criteria.setAccuracy(Criteria.ACCURACY_FINE); // 设置是否要求速度 criteria.setSpeedRequired(false); // 设置是否允许运营商收费 criteria.setCostAllowed(false); // 设置是否需要方位信息 criteria.setBearingRequired(false); // 设置是否需要海拔信息 criteria.setAltitudeRequired(false); // 设置对电源的需求 criteria.setPowerRequirement(Criteria.POWER_LOW); return criteria; }
Example #17
Source File: Geolocation.java From OsmGo with MIT License | 6 votes |
/** * Given the call's options, return a Criteria object * that will indicate which location provider we need to use. * @param call * @return */ private Criteria getCriteriaForCall(PluginCall call) { boolean enableHighAccuracy = call.getBoolean("enableHighAccuracy", false); boolean altitudeRequired = call.getBoolean("altitudeRequired", false); boolean speedRequired = call.getBoolean("speedRequired", false); boolean bearingRequired = call.getBoolean("bearingRequired", false); int timeout = call.getInt("timeout", 30000); int maximumAge = call.getInt("maximumAge", 0); Criteria c = new Criteria(); c.setAccuracy(enableHighAccuracy ? Criteria.ACCURACY_FINE : Criteria.ACCURACY_COARSE); c.setAltitudeRequired(altitudeRequired); c.setBearingRequired(bearingRequired); c.setSpeedRequired(speedRequired); return c; }
Example #18
Source File: LocationSensor.java From appinventor-extensions with Apache License 2.0 | 6 votes |
/** * Creates a new LocationSensor component with a default state of <code>enabled</code>. * * @param container ignored (because this is a non-visible component) * @param enabled true if the LocationSensor is enabled by default, otherwise false. */ public LocationSensor(ComponentContainer container, boolean enabled) { super(container.$form()); this.enabled = enabled; handler = new Handler(); // Set up listener form.registerForOnResume(this); form.registerForOnStop(this); // Initialize sensor properties (60 seconds; 5 meters) timeInterval = 60000; distanceInterval = 5; // Initialize location-related fields Context context = container.$context(); geocoder = new Geocoder(context); locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); locationCriteria = new Criteria(); myLocationListener = new MyLocationListener(); allProviders = new ArrayList<String>(); // Do some initialization depending on the initial enabled state Enabled(enabled); }
Example #19
Source File: GpsTraceService.java From MobileGuard with MIT License | 6 votes |
@Override public void onCreate() { super.onCreate(); // locate locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // check permission if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } // get best provider Criteria criteria = new Criteria(); criteria.setCostAllowed(true); criteria.setAccuracy(Criteria.ACCURACY_FINE); String bestProvider = locationManager.getBestProvider(criteria, true); System.out.println("best provider:" + bestProvider); // start listening listener = new MyLocationListener(); locationManager.requestLocationUpdates(bestProvider, 0, 0, listener); }
Example #20
Source File: Util.java From letv with Apache License 2.0 | 6 votes |
public static String getLocation(Context context) { if (context == null) { return ""; } try { LocationManager locationManager = (LocationManager) context.getSystemService(HOME_RECOMMEND_PARAMETERS.LOCATION); Criteria criteria = new Criteria(); criteria.setCostAllowed(false); criteria.setAccuracy(2); String bestProvider = locationManager.getBestProvider(criteria, true); if (bestProvider != null) { Location lastKnownLocation = locationManager.getLastKnownLocation(bestProvider); if (lastKnownLocation == null) { return ""; } double latitude = lastKnownLocation.getLatitude(); g = latitude + "*" + lastKnownLocation.getLongitude(); return g; } } catch (Throwable e) { f.b("getLocation", "getLocation>>>", e); } return ""; }
Example #21
Source File: ShowLocationActivity.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); latituteField = (TextView) findViewById(R.id.TextView02); longitudeField = (TextView) findViewById(R.id.TextView04); // Get the location manager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Define the criteria how to select the locatioin provider -> use // default Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, false); Location location = locationManager.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { System.out.println("Provider " + provider + " has been selected."); onLocationChanged(location); } else { latituteField.setText("Location not available"); longitudeField.setText("Location not available"); } }
Example #22
Source File: LocationProvider.java From open-quartz with Apache License 2.0 | 6 votes |
public LocationProvider(Context context) { mLocationManager = (LocationManager) context .getSystemService(Context.LOCATION_SERVICE); mGeocoder = new Geocoder(context); final Criteria criteria = new Criteria(); mBestProvider = mLocationManager.getBestProvider(criteria, true); final List<String> providers = mLocationManager.getProviders( criteria, true); for (String provider : providers) { // mLocationManager.requestLocationUpdates(provider, 0, 0, this); } }
Example #23
Source File: GeoLocation.java From Acastus with GNU Lesser General Public License v3.0 | 6 votes |
public void updateLocation(){ Criteria criteria = new Criteria(); String bestProvider = String.valueOf(locationManager.getBestProvider(criteria, true)).toString(); try { locationManager.requestLocationUpdates(bestProvider, 60000, 15, this); Handler h = new Handler(Looper.getMainLooper()); h.post(new Runnable() { public void run() { Toast.makeText(context, R.string.accessing_location, Toast.LENGTH_SHORT).show(); } }); }catch (SecurityException e){ } }
Example #24
Source File: MapLocationUtil.java From lunzi with Apache License 2.0 | 6 votes |
private String getProvider(LocationManager locationManager) { // 构建位置查询条件 Criteria criteria = new Criteria(); // 查询精度:高 criteria.setAccuracy(Criteria.ACCURACY_FINE); // 速度 criteria.setSpeedRequired(false); // 是否查询海拨:否 criteria.setAltitudeRequired(false); // 是否查询方位角:否 criteria.setBearingRequired(false); // 电量要求:低 criteria.setPowerRequirement(Criteria.POWER_LOW); // 返回最合适的符合条件的provider,第2个参数为true说明,如果只有一个provider是有效的,则返回当前provider return locationManager.getBestProvider(criteria, true); }
Example #25
Source File: HostGeolocationProfile.java From DeviceConnect-Android with MIT License | 6 votes |
/** * 位置情報取得開始. * @param accuracy 精度. * @param interval 受信間隔. */ private void startGPS(final boolean accuracy, final int interval) { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } Criteria criteria = new Criteria(); if (accuracy) { criteria.setAccuracy(Criteria.ACCURACY_FINE); } else { criteria.setAccuracy(Criteria.ACCURACY_COARSE); } mLocationManager.requestLocationUpdates(mLocationManager.getBestProvider(criteria, true), interval, 0, this, Looper.getMainLooper()); }
Example #26
Source File: LocationLogic.java From redalert-android with Apache License 2.0 | 6 votes |
public static Location GetLastKnownLocation(Context context) { // Get location manager LocationManager locationManager = (LocationManager) context.getSystemService(context.LOCATION_SERVICE); // Create location criteria Criteria criteria = new Criteria(); // Set fine accuracy criteria.setAccuracy(criteria.ACCURACY_FINE); // Get best provider String bestProvider = locationManager.getBestProvider(criteria, false); // No provider? if (bestProvider == null) { // Return null return null; } // Return last location return locationManager.getLastKnownLocation(bestProvider); }
Example #27
Source File: LocationInfo.java From batteryhub with Apache License 2.0 | 5 votes |
public static String getBestProvider(Context context) { LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); return manager.getBestProvider(criteria, true); }
Example #28
Source File: LocationProviderV1.java From android_packages_apps_UnifiedNlp with Apache License 2.0 | 5 votes |
@Override public boolean onMeetsCriteria(Criteria criteria) { if (criteria.getAccuracy() == Criteria.ACCURACY_FINE) { return false; } return true; }
Example #29
Source File: AbstractBarterLiFragment.java From barterli_android with Apache License 2.0 | 5 votes |
public boolean isLocationServiceEnabled() { LocationManager lm = (LocationManager) getActivity() .getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = lm.getBestProvider(criteria, true); return ((provider != null) && !LocationManager.PASSIVE_PROVIDER .equals(provider)); }
Example #30
Source File: EditCameraLocationActivity.java From evercam-android with GNU Affero General Public License v3.0 | 5 votes |
public void addMyLocationButtonClickListner() { mMap.setOnMyLocationButtonClickListener(new GoogleMap.OnMyLocationButtonClickListener() { @Override public boolean onMyLocationButtonClick() { //TODO: Any custom actions if (ActivityCompat.checkSelfPermission(EditCameraLocationActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(EditCameraLocationActivity.this, android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mMap.clear(); LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = locationManager.getBestProvider(criteria, false); location = locationManager.getLastKnownLocation(provider); if (location != null) { mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 15)); LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude()); tappedLatLng = latLng; mMap.addMarker(new MarkerOptions().position(latLng)); new CallMashapeAsync().execute(); } else { //Location Object is null May call Location Listener here } } return false; } }); }