List of usage examples for android.location Criteria Criteria
public Criteria()
From source file:com.example.angel.parkpanda.MainActivity.java
public Location moveMyPosCamera() { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return null; }//from w ww . j a va2 s. c om Location myLocation = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (myLocation == null) { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); String provider = lm.getBestProvider(criteria, true); myLocation = lm.getLastKnownLocation(provider); } return myLocation; }
From source file:org.mariotaku.twidere.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 w w w. jav a 2s. co m private boolean getLocation() { final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); final String provider = mLocationManager.getBestProvider(criteria, true); if (provider != null) { final Location location; if (mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } else { location = mLocationManager.getLastKnownLocation(provider); } if (location == null) { mLocationManager.requestLocationUpdates(provider, 0, 0, this); setSupportProgressBarIndeterminateVisibility(true); } mRecentLocation = location != null ? new ParcelableLocation(location) : null; } else { Toast.makeText(this, R.string.cannot_get_location, Toast.LENGTH_SHORT).show(); } return provider != null; }
From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java
public boolean isLocationEnabled(Context context) { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); String provider = lm.getBestProvider(new Criteria(), true); return (!TextUtils.isEmpty(provider) && !LocationManager.PASSIVE_PROVIDER.equals(provider)); }
From source file:it.geosolutions.geocollect.android.core.mission.PendingMissionListActivity.java
/** * Get provider name./*from w w w .ja v a2s.com*/ * @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. *///from ww w .j a v a 2 s . c o m 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 ww w .ja v a 2s . com*/ 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:com.example.sensingapp.SensingApp.java
private boolean getGPSProvider() { Location location = null;// w ww. ja va 2s .c o m Criteria crit = new Criteria(); float fLat, fLng, fAlt; m_sGPSProvider = m_locManager.getBestProvider(crit, true); //false? if (m_sGPSProvider != null) { m_blnGPSSignalEnabled = true; location = m_locManager.getLastKnownLocation(m_sGPSProvider); if (location != null) { fLat = (float) (location.getLatitude()); fLng = (float) (location.getLongitude()); if (location.hasAltitude()) { fAlt = (float) (location.getAltitude()); } } return true; } else { m_chkGPS.setEnabled(false); return false; } }
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 ww .ja v a 2 s . c o m 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 . jav a2 s . c om*/ 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. **/// ww w. j a 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; }