List of usage examples for android.location Criteria setAccuracy
public void setAccuracy(int accuracy)
From source file:org.akvo.flow.ui.fragment.SurveyedLocaleListFragment.java
@Override public void onResume() { super.onResume(); mDatabase.open();//from w w w .j av a 2s . c o m // try to find out where we are Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); String provider = mLocationManager.getBestProvider(criteria, true); if (provider != null) { Location loc = mLocationManager.getLastKnownLocation(provider); if (loc != null) { mLatitude = loc.getLatitude(); mLongitude = loc.getLongitude(); } } mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this); // Listen for data sync updates, so we can update the UI accordingly getActivity().registerReceiver(dataSyncReceiver, new IntentFilter(getString(R.string.action_data_sync))); refresh(); }
From source file:com.careme.apvereda.careme.AccumulatorService.java
@Override public int onStartCommand(Intent intenc, int flags, int idArranque) { SharedPreferences sharedPref = getApplicationContext().getSharedPreferences("basicData", Context.MODE_PRIVATE); String email = sharedPref.getString("email", ""); //Uncomment to use Nimbees features /*if (email.compareTo("") != 0) { try {/*www . j a v a 2 s .c om*/ // Initialize library calling the init method on the Nimbees Client NimbeesClient.init(this); } catch (NimbeesException e) { e.printStackTrace(); } NimbeesClient.getUserManager().register("email", new NimbeesRegistrationCallback() { @Override public void onSuccess() { /* Registration was successful! Toast.makeText(getApplicationContext(), "xito en el registro", Toast.LENGTH_LONG).show(); } @Override public void onFailure(NimbeesException failure) { /* Registration failed Toast.makeText(getApplicationContext(), "Fallo en el registro", Toast.LENGTH_LONG).show(); } }); } */ //Toast.makeText(this,"Servicio arrancado "+ idArranque, Toast.LENGTH_SHORT).show(); // Obtain a reference to the Location Manager locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria crit = new Criteria(); crit.setAccuracy(Criteria.ACCURACY_FINE); crit.setPowerRequirement(Criteria.POWER_LOW); provider = locManager.getBestProvider(crit, true); // And register to obtain current location updates locListener = new LocationListener() { public void onLocationChanged(Location loc) { // Insert a new entry on History History history = new History(loc.getLatitude(), loc.getLongitude(), new Date()); db.insertHistory(history); //Uncomment to use Nimbees features /* try { sendPersonalizado(loc); } catch (Exception e) { }*/ /* Monitor makes the monitoring of the user to determine if he/she has lost */ monitor(loc); } @Override public void onStatusChanged(String provider, int stat, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; // We want to update the current location every time the user moves MIN_DISTANCE locManager.requestLocationUpdates(provider, 0, MIN_DISTANCE, locListener); return START_STICKY; }
From source file:com.metinkale.prayerapp.vakit.AddCity.java
@SuppressWarnings("MissingPermission") public void checkLocation() { if (PermissionUtils.get(this).pLocation) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Location loc = null;/*from w w w. j a v a 2s . c o m*/ List<String> providers = lm.getProviders(true); for (String provider : providers) { Location last = lm.getLastKnownLocation(provider); // one hour==1meter in accuracy if ((last != null) && ((loc == null) || ((last.getAccuracy() - (last.getTime() / (1000 * 60 * 60))) < (loc.getAccuracy() - (loc.getTime() / (1000 * 60 * 60)))))) { loc = last; } } if (loc != null) onLocationChanged(loc); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_MEDIUM); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(false); criteria.setSpeedRequired(false); String provider = lm.getBestProvider(criteria, true); if (provider != null) { lm.requestSingleUpdate(provider, this, null); } } else { PermissionUtils.get(this).needLocation(this); } }
From source file:com.johan.vertretungsplan_2.SelectSchoolActivity.java
private void showListGeo() { final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); // no GPS final String provider = locationManager.getBestProvider(criteria, true); if (provider == null) { Log.d("vertretungsplan", "provider==null"); tvLocateString.setText(R.string.geolocate_disabled); status = Status.LIST;/*from w w w. j a va2s . c om*/ return; } locationManager.requestLocationUpdates(provider, 0, 0, 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) { if (!visible) return; if (location != null) { double lat = location.getLatitude(); double lon = location.getLongitude(); for (Schule school : schools) { float[] result = new float[1]; Location.distanceBetween(lat, lon, school.getGeo()[0], school.getGeo()[1], result); school.setDistance(result[0]); Log.d("vertretungsplan", school.getName() + ": " + school.getDistance()); } Collections.sort(schools, new DistanceSchoolComparator()); lstSchools.setAdapter(new SchoolsAdapter(SelectSchoolActivity.this, schools, true)); } tvLocateString.setText(R.string.alphabetic_list); ivLocationIcon.setImageResource(R.drawable.ic_action_view_as_list); status = Status.GEO; } }); }
From source file:org.deviceconnect.android.deviceplugin.host.profile.HostGeolocationProfile.java
/** * ??.//from w w w .j a va2s. c om * @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()); }
From source file:com.facebook.android.Places.java
public void getLocation() { /*/*from w w w .ja v a 2s .c o m*/ * launch a new Thread to get new location */ new Thread() { @Override public void run() { Looper.prepare(); dialog = ProgressDialog.show(Places.this, "", getString(R.string.fetching_location), false, true, new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { showToast("No location fetched."); } }); if (lm == null) { lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); } if (locationListener == null) { locationListener = new MyLocationListener(); } Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); String provider = lm.getBestProvider(criteria, true); if (provider != null && lm.isProviderEnabled(provider)) { lm.requestLocationUpdates(provider, 1, 0, locationListener, Looper.getMainLooper()); } else { /* * GPS not enabled, prompt user to enable GPS in the * Location menu */ new AlertDialog.Builder(Places.this).setTitle(R.string.enable_gps_title) .setMessage(getString(R.string.enable_gps)) .setPositiveButton(R.string.gps_settings, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivityForResult( new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); Places.this.finish(); } }).show(); } Looper.loop(); } }.start(); }
From source file:com.quantcast.measurement.service.QCLocation.java
void setupLocManager(Context appContext) { if (appContext == null) return;/*from ww w .jav a2 s . co m*/ _locManager = (LocationManager) appContext.getSystemService(Context.LOCATION_SERVICE); if (_locManager != null) { //specifically set our Criteria. All we need is a general location Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(false); criteria.setPowerRequirement(Criteria.NO_REQUIREMENT); criteria.setSpeedRequired(false); _myProvider = _locManager.getBestProvider(criteria, true); _geocoder = new Geocoder(appContext); } QCLog.i(TAG, "Setting location provider " + _myProvider); }
From source file:org.deviceconnect.android.deviceplugin.host.profile.HostGeolocationProfile.java
/** * ?????.//w w w.j a va 2 s. co m * @param accuracy . * @param response ?. */ private void getGPS(final boolean accuracy, final Intent response) { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { MessageUtils.setIllegalDeviceStateError(response, "ACCESS_FINE_LOCATION permission not granted."); sendResponse(response); return; } Criteria criteria = new Criteria(); if (accuracy) { criteria.setAccuracy(Criteria.ACCURACY_FINE); } else { criteria.setAccuracy(Criteria.ACCURACY_COARSE); } mLocationManager.requestSingleUpdate(mLocationManager.getBestProvider(criteria, true), new LocationListener() { @Override public void onLocationChanged(Location location) { Bundle position = createPositionObject(location); DConnectProfile.setResult(response, DConnectMessage.RESULT_OK); response.putExtra(GeolocationProfile.PARAM_POSITION, position); sendResponse(response); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // NOP } @Override public void onProviderEnabled(String provider) { // NOP } @Override public void onProviderDisabled(String provider) { // NOP } }, Looper.getMainLooper()); }
From source file:org.akvo.flow.activity.GeoshapeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.geoshape_activity); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mFeatures = new ArrayList<>(); mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); mFeatureMenu = findViewById(R.id.feature_menu); mFeatureName = (TextView) findViewById(R.id.feature_name); mClearPointBtn = findViewById(R.id.clear_point_btn); mClearPointBtn.setOnClickListener(mFeatureMenuListener); findViewById(R.id.add_point_btn).setOnClickListener(mFeatureMenuListener); findViewById(R.id.clear_feature_btn).setOnClickListener(mFeatureMenuListener); findViewById(R.id.properties).setOnClickListener(mFeatureMenuListener); mAllowPoints = getIntent().getBooleanExtra(ConstantUtil.EXTRA_ALLOW_POINTS, true); mAllowLine = getIntent().getBooleanExtra(ConstantUtil.EXTRA_ALLOW_LINE, true); mAllowPolygon = getIntent().getBooleanExtra(ConstantUtil.EXTRA_ALLOW_POLYGON, true); mManualInput = getIntent().getBooleanExtra(ConstantUtil.EXTRA_MANUAL_INPUT, true); initMap();// w w w.j a va 2 s . c o m String geoJSON = getIntent().getStringExtra(ConstantUtil.GEOSHAPE_RESULT); if (!TextUtils.isEmpty(geoJSON)) { load(geoJSON); } else { // If user location is known, center map LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); String provider = manager.getBestProvider(criteria, true); if (provider != null) { Location location = manager.getLastKnownLocation(provider); if (location != null) { LatLng position = new LatLng(location.getLatitude(), location.getLongitude()); mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(position, 10)); } } } }
From source file:net.mceoin.cominghome.LocationService.java
private void backgroundThreadProcessing() { secondsToSleep = 30;//w ww . j a v a 2 s .co m while (runBackgroundThread) { if (locationManager == null) { initLocationManager(); } try { if (debug) Log.d(TAG, "sleeping " + secondsToSleep + " seconds"); Thread.sleep(secondsToSleep * 1000); if (secondsToSleep < MAXSLEEP_WHILE_NOT_MOVING) { secondsToSleep += 15; } } catch (InterruptedException e) { // e.printStackTrace(); if (debug) Log.d(TAG, "wake up!"); } Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); String provider = locationManager.getBestProvider(criteria, true); // provider = LocationManager.GPS_PROVIDER; Location location = locationManager.getLastKnownLocation(provider); if (mLocationClient.isConnected()) { if (debug) Log.d(TAG, "mLocationClient is connected"); location = mLocationClient.getLastLocation(); } if (debug) Log.d(TAG, "location=" + location); if (myLocation == null) { myLocation = location; broadcastLocationChanged(myLocation); } else { float dist = distFrom(myLocation, location); if (debug) Log.d(TAG, "dist=" + dist); if ((checkinRequested) || (dist > 20)) { myLocation = location; broadcastLocationChanged(myLocation); checkinRequested = false; if (secondsToSleep > MAXSLEEP_WHILE_MOVING) { // if we're moving, don't sleep too much secondsToSleep = MAXSLEEP_WHILE_MOVING; } } } } }