List of usage examples for android.location Criteria setAccuracy
public void setAccuracy(int accuracy)
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 . java2 s.co 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: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. *//* www. j a v a 2s . co 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:com.mibr.android.intelligentreminder.INeedToo.java
public LocationManager getLocationManager() { if (mLocationManager == null) { mLocationManager = (android.location.LocationManager) getSystemService(Context.LOCATION_SERVICE); }//from w w w.j a va 2s . co m if (_bestProvider == null) { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); _bestProvider = mLocationManager.getBestProvider(criteria, false); mLocationManager.requestLocationUpdates(_bestProvider, 20000, 10, this); } return mLocationManager; }
From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java
@Override protected void onResume() { super.onResume(); try {/*from w w w . j a v a2 s. co m*/ this.mWakeLock.acquire(); // ?? ? killOnError(); // ? ? mixContext.mixView = this; // ?? dataView.doStart(); // ?? dataView.clearEvents(); // ? ? double angleX, angleY; // ? x, y /*? ? ? */ angleX = Math.toRadians(-90); m1.set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f, (float) Math.sin(angleX), (float) Math.cos(angleX)); angleX = Math.toRadians(-90); angleY = Math.toRadians(-90); m2.set(1f, 0f, 0f, 0f, (float) Math.cos(angleX), (float) -Math.sin(angleX), 0f, (float) Math.sin(angleX), (float) Math.cos(angleX)); m3.set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f, (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY)); m4.toIdentity(); for (int i = 0; i < histR.length; i++) { histR[i] = new Matrix(); } /* */ // ? sensorMgr = (SensorManager) getSystemService(SENSOR_SERVICE); // ? ? // ?? sensors = sensorMgr.getSensorList(Sensor.TYPE_ACCELEROMETER); if (sensors.size() > 0) { sensorGrav = sensors.get(0); } // ? sensors = sensorMgr.getSensorList(Sensor.TYPE_MAGNETIC_FIELD); if (sensors.size() > 0) { sensorMag = sensors.get(0); } //// TODO: 2016-06-01 if (sensors.size() > 0) { sensors = sensorMgr_ori.getSensorList(Sensor.TYPE_ORIENTATION); orientationSensor = sensors.get(0); } // ?? ? ? ? ? sensorMgr.registerListener(this, sensorGrav, SENSOR_DELAY_GAME); sensorMgr.registerListener(this, sensorMag, SENSOR_DELAY_GAME); if (orientationSensor != null) { sensorMgr_ori.registerListener(this, orientationSensor, sensorMgr_ori.SENSOR_DELAY_GAME); } try { // ?? (Criteria) // http://developer.android.com/reference/android/location/Criteria.html Criteria c = new Criteria(); // ? c.setAccuracy(Criteria.ACCURACY_FINE); //c.setBearingRequired(true); // ? locationMgr = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // ?? ? ? ? . 2 , 3 locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 4, this); // ?? ? , String bestP = locationMgr.getBestProvider(c, true); isGpsEnabled = locationMgr.isProviderEnabled(bestP); // gps, ? ? ? Location hardFix = new Location("reverseGeocoded"); try { // ? gps, ?? Location gps = locationMgr.getLastKnownLocation(LocationManager.GPS_PROVIDER); Location network = locationMgr.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); // ? ? // gps > ? > if (gps != null) mixContext.curLoc = gps; else if (network != null) mixContext.curLoc = network; else mixContext.curLoc = hardFix; } catch (Exception ex2) { // ? ex2.printStackTrace(); // mixContext.curLoc = hardFix; // } // ? ? ?? mixContext.setLocationAtLastDownload(mixContext.curLoc); // ?? . ? GeomagneticField gmf = new GeomagneticField((float) mixContext.curLoc.getLatitude(), (float) mixContext.curLoc.getLongitude(), (float) mixContext.curLoc.getAltitude(), System.currentTimeMillis()); // ?? angleY = Math.toRadians(-gmf.getDeclination()); m4.set((float) Math.cos(angleY), 0f, (float) Math.sin(angleY), 0f, 1f, 0f, (float) -Math.sin(angleY), 0f, (float) Math.cos(angleY)); mixContext.declination = gmf.getDeclination(); } catch (Exception ex) { Log.d("mixare", "GPS Initialize Error", ex); // ? } // ? downloadThread = new Thread(mixContext.downloadManager); downloadThread.start(); } catch (Exception ex) { doError(ex); // ? try { // ??? if (sensorMgr != null) { sensorMgr.unregisterListener(this, sensorGrav); sensorMgr.unregisterListener(this, sensorMag); sensorMgr = null; } // ?? if (locationMgr != null) { locationMgr.removeUpdates(this); locationMgr = null; } // ?? ?? if (mixContext != null) { if (mixContext.downloadManager != null) mixContext.downloadManager.stop(); } } catch (Exception ignore) { } } // ?? // ?? ? ( ?? ) ? if (dataView.isFrozen() && searchNotificationTxt == null) { searchNotificationTxt = new TextView(this); searchNotificationTxt.setWidth(dWindow.getWidth()); searchNotificationTxt.setPadding(10, 2, 0, 0); searchNotificationTxt.setBackgroundColor(Color.DKGRAY); searchNotificationTxt.setTextColor(Color.WHITE); searchNotificationTxt.setOnTouchListener(this); addContentView(searchNotificationTxt, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } else if (!dataView.isFrozen() && searchNotificationTxt != null) { searchNotificationTxt.setVisibility(View.GONE); searchNotificationTxt = 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 w w. ja v a 2s. c om*/ 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.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. **///w w w .j a va 2s . c om 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) {//w w w . ja va 2 s .c o m 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; }