List of usage examples for android.location Criteria ACCURACY_FINE
int ACCURACY_FINE
To view the source code for android.location Criteria ACCURACY_FINE.
Click Source Link
From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListActivity.java
/** * Get provider name.//w ww .j a v a 2s . co m * @return Name of best suiting provider. * */ String getProviderName() { LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setPowerRequirement(Criteria.POWER_LOW); // Chose your desired power consumption level. criteria.setAccuracy(Criteria.ACCURACY_FINE); // Choose your accuracy requirement. criteria.setSpeedRequired(false); // Chose if speed for first location fix is required. criteria.setAltitudeRequired(false); // Choose if you use altitude. criteria.setBearingRequired(false); // Choose if you use bearing. criteria.setCostAllowed(false); // Choose if this provider can waste money :-) // Provide your criteria and flag enabledOnly that tells // LocationManager only to return active providers. return locationManager.getBestProvider(criteria, true); }
From source file:org.getlantern.firetweet.activity.support.ComposeActivity.java
/** * The Location Manager manages location providers. This code searches for * the best provider of data (GPS, WiFi/cell phone tower lookup, some other * mechanism) and finds the last known location. *//* ww w . j a v a2s. c om*/ private boolean startLocationUpdateIfEnabled() { final LocationManager lm = mLocationManager; final boolean attachLocation = mPreferences.getBoolean(KEY_ATTACH_LOCATION, false); if (!attachLocation) { lm.removeUpdates(this); return false; } final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); final String provider = lm.getBestProvider(criteria, true); if (provider != null) { mLocationText.setText(R.string.getting_location); lm.requestLocationUpdates(provider, 0, 0, this); final Location location; if (lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } else { location = lm.getLastKnownLocation(provider); } if (location != null) { onLocationChanged(location); } } else { Toast.makeText(this, R.string.cannot_get_location, Toast.LENGTH_SHORT).show(); } return provider != null; }
From source file:org.mariotaku.twidere.activity.support.ComposeActivity.java
/** * The Location Manager manages location providers. This code searches for * the best provider of data (GPS, WiFi/cell phone tower lookup, some other * mechanism) and finds the last known location. *//*from w ww. j a va 2 s . c o m*/ private boolean startLocationUpdateIfEnabled() { final LocationManager lm = mLocationManager; final boolean attachLocation = mPreferences.getBoolean(KEY_ATTACH_LOCATION); if (!attachLocation) { lm.removeUpdates(this); return false; } final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); final String provider = lm.getBestProvider(criteria, true); if (provider != null) { mLocationText.setText(R.string.getting_location); lm.requestLocationUpdates(provider, 0, 0, this); final Location location; if (lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { location = lm.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } else { location = lm.getLastKnownLocation(provider); } if (location != null) { onLocationChanged(location); } } else { Toast.makeText(this, R.string.cannot_get_location, Toast.LENGTH_SHORT).show(); } return provider != null; }
From source file:reportsas.com.formulapp.Formulario.java
public void HabilitarParametros(Menu menu) { for (int i = 0; i < encuesta.getParametros().size(); i++) { switch (encuesta.getParametros().get(i).getIdParametro()) { // Captura GPS case 1:/* w w w. j a v a2s . c om*/ menu.getItem(2).setVisible(true); parametroGPS = new ParametrosRespuesta(1); manejador = (LocationManager) getSystemService(LOCATION_SERVICE); if (!manejador.isProviderEnabled(LocationManager.GPS_PROVIDER)) { AlertDialog alert = null; final AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("El sistema GPS esta desactivado, Debe activarlo!").setCancelable(false) .setPositiveButton("Activar GPS", new DialogInterface.OnClickListener() { public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) { startActivity( new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } }); alert = builder.create(); alert.show(); } Criteria criterio = new Criteria(); criterio.setCostAllowed(false); criterio.setAltitudeRequired(false); criterio.setAccuracy(Criteria.ACCURACY_FINE); proveedor = manejador.getBestProvider(criterio, true); Location localizacion = manejador.getLastKnownLocation(proveedor); capturarLocalizacion(localizacion); manejador.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, this); Toast toast1; if (parametroGPS.getValor().equals("Posicion Desconocida")) { toast1 = Toast.makeText(this, "Posicion Desconocida.", Toast.LENGTH_SHORT); } else { toast1 = Toast.makeText(this, "Localizacin obtenida exitosamente.", Toast.LENGTH_SHORT); } toast1.show(); break; // Captura Imgen case 2: menu.getItem(0).setVisible(true); break; // Lectura de Codigo case 3: menu.getItem(1).setVisible(true); break; default: break; } } }
From source file:com.BeatYourRecord.SubmitActivity.java
private void getVideoLocation() { this.locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false);/*from w w w.j a v a 2 s. c o m*/ criteria.setSpeedRequired(false); criteria.setCostAllowed(true); String provider = locationManager.getBestProvider(criteria, true); this.locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { if (location != null) { SubmitActivity.this.videoLocation = location; lat = location.getLatitude(); lng = location.getLongitude(); Log.d(LOG_TAG, "lat=" + lat); Log.d(LOG_TAG, "lng=" + lng); TextView locationText = (TextView) findViewById(R.id.locationLabel); locationText.setText("Geo Location: " + String.format("lat=%.2f lng=%.2f", lat, lng)); locationManager.removeUpdates(this); } else { Log.d(LOG_TAG, "location is null"); } } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }; if (provider != null) { locationManager.requestLocationUpdates(provider, 2000, 10, locationListener); } }
From source file:com.dwdesign.tweetings.activity.ComposeActivity.java
/** * The Location Manager manages location providers. This code searches for * the best provider of data (GPS, WiFi/cell phone tower lookup, some other * mechanism) and finds the last known location. **///from www .ja v a 2 s.c o m private boolean getLocation() { final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); final String provider = mLocationManager.getBestProvider(criteria, true); if (provider != null) { mRecentLocation = mLocationManager.getLastKnownLocation(provider); } else { Toast.makeText(this, R.string.cannot_get_location, Toast.LENGTH_SHORT).show(); } return provider != null; }
From source file:com.thomasokken.free42.Free42Activity.java
public int shell_get_location(DoubleHolder lat, DoubleHolder lon, DoubleHolder lat_lon_acc, DoubleHolder elev, DoubleHolder elev_acc) {/*from w w w . j a va 2 s . c om*/ if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { locat_inited = false; ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, MY_PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION); return 0; } if (!locat_inited) { locat_inited = true; LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria cr = new Criteria(); cr.setAccuracy(Criteria.ACCURACY_FINE); String provider = lm.getBestProvider(cr, true); if (provider == null) { locat_exists = false; return 0; } LocationListener ll = new LocationListener() { public void onLocationChanged(Location location) { // TODO: Verify units etc. locat_lat = location.getLatitude(); locat_lon = location.getLongitude(); locat_lat_lon_acc = location.getAccuracy(); locat_elev = location.getAltitude(); locat_elev_acc = location.hasAltitude() ? locat_lat_lon_acc : -1; } public void onProviderDisabled(String provider) { // Ignore } public void onProviderEnabled(String provider) { // Ignore } public void onStatusChanged(String provider, int status, Bundle extras) { // Ignore } }; try { lm.requestLocationUpdates(provider, 60000, 1, ll, Looper.getMainLooper()); } catch (IllegalArgumentException e) { return 0; } catch (SecurityException e) { return 0; } locat_exists = true; } if (locat_exists) { lat.value = locat_lat; lon.value = locat_lon; lat_lon_acc.value = locat_lat_lon_acc; elev.value = locat_elev; elev_acc.value = locat_elev_acc; return 1; } else return 0; }