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:reportsas.com.formulapp.Formulario.java
public void CapturaL() { if (parametroGPS == null) { parametroGPS = new ParametrosRespuesta(1); manejador = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criterio = new Criteria(); criterio.setCostAllowed(false);//from w w w.j ava 2 s . c om criterio.setAltitudeRequired(false); criterio.setAccuracy(Criteria.ACCURACY_FINE); proveedor = manejador.getBestProvider(criterio, true); Location localizacion = manejador.getLastKnownLocation(proveedor); capturarLocalizacion(localizacion); } Intent intentoDlgUno = new Intent(this, dialogUbicacion.class); intentoDlgUno.putExtra("location", parametroGPS.getValor()); startActivityForResult(intentoDlgUno, 0); }
From source file:com.anton.gavel.GavelMain.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @Override/*from w w w.j ava 2s .c o m*/ public void onClick(View arg0) { //click listener for location button LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); //String provider = locationManager.getBestProvider(criteria, true); locationManager.requestSingleUpdate(criteria, new LocationListener() { @Override public void onLocationChanged(Location location) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) createDialog(DIALOG_NO_GEOCODING); else if (Geocoder.isPresent()) (new ReverseGeocodingTask(getBaseContext())).execute(new Location[] { location }); // Invoking reverse geocoding in an AsyncTask. } @Override public void onProviderDisabled(String provider) { } @Override public void onProviderEnabled(String provider) { } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } }, null); }
From source file:net.jongrakko.zipsuri.activity.PostUploadActivity.java
@Override public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) { if (isChecked) { switch (buttonView.getId()) { case R.id.radioButtonAddressGPS: mEditTextAddress.setOnClickListener(null); this.mGoogleMap.setOnMapClickListener(this); this.mGoogleMap.setOnMyLocationButtonClickListener(this); if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { mGoogleMap.setMyLocationEnabled(true); LocationProvider lprovider; LocationManager lm = (LocationManager) getActivity() .getSystemService(getActivity().LOCATION_SERVICE); lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); String provider;//from www . j a va2s . c o m Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_HIGH); provider = lm.getBestProvider(criteria, true); if (provider == null || provider.equals("passive")) { // ? ? ?? new AlertDialog.Builder(getActivity()).setTitle(" ??") .setNeutralButton("??", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { buttonView.toggle(); startActivityForResult( new Intent( android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS), 0); } }).setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { dialog.dismiss(); } }).show(); } else { // ? ? lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, this); Location l = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (l != null) { Log.e("hello??", "okok"); } } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { requestPermissions(new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, MY_LOCATION_REQUEST_CODE); } } break; case R.id.radioButtonAddressSelf: this.mGoogleMap.setOnMapClickListener(null); mEditTextAddress.setOnClickListener(this); this.mGoogleMap.setOnMyLocationButtonClickListener(null); mGoogleMap.setMyLocationEnabled(false); mEditTextAddress.setOnClickListener(this); startActivityForResult(new Intent(getContext(), SearchAddressActivity.class), SEARCH_ADDRESS); break; } } }
From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java
@Override protected void onResume() { super.onResume(); try {/*w w w . j a va 2 s. c o 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:com.marianhello.cordova.bgloc.LocationUpdateService.java
/** * TODO Experimental cell-tower change system; something like ios significant changes. *//*from ww w . java2s . c o m*/ public void onCellLocationChange(CellLocation cellLocation) { Log.i(TAG, "- onCellLocationChange" + cellLocation.toString()); if (isDebugging) { Toast.makeText(this, "Cellular location change", Toast.LENGTH_LONG).show(); startTone("chirp_chirp_chirp"); } if (!isMoving && stationaryLocation != null) { criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH); criteria.setPowerRequirement(Criteria.POWER_HIGH); locationManager.requestSingleUpdate(criteria, singleUpdatePI); } }
From source file:com.moodmap.HomeActivity.java
private void registerLocationListeners() { mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (mLocationListener_Fine == null) { mLocationListener_Fine = new LocationListener() { // LocationListener @Override//from w w w. j a v a 2s . c o m public void onLocationChanged(Location location) { float currentLocationAccuracy = location.getAccuracy(); myLocationFixCnt_Fine++; if ((myLocationFixCnt_Fine >= Constants.kMaxGpsFixCnt) || ((location.hasAccuracy()) && (currentLocationAccuracy <= 60.0))) // tighter, // slower // location { // stop the fine location service mLocationManager.removeUpdates(this); // also stop the coarse location updates, if for some // reason it has not resolved yet if (mLocationListener_Coarse != null) { mLocationManager.removeUpdates(mLocationListener_Coarse); } } updateMyLocation(location); } @Override public void onProviderDisabled(String provider) { Log.v(Constants.LOGTAG, "Fine Provider Disabled: " + provider); } @Override public void onProviderEnabled(String provider) { Log.v(Constants.LOGTAG, "Fine Provider Enabled: " + provider); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { myStatusChangeCnt_Fine++; if ((status == LocationProvider.OUT_OF_SERVICE)) // not sure if needed (myStatusChangeCnt_Fine >= // Constants.kMaxGpsFixCnt)) { // if cannot resolve the location, do not leave the gps // running mLocationManager.removeUpdates(mLocationListener_Fine); } Log.v(Constants.LOGTAG, "Fine Provider Status Change (OVER): " + provider + " status:" + status + " myStatusChangeCnt_Fine:" + myStatusChangeCnt_Fine); // LocationProvider.OUT_OF_SERVICE } }; } if (mLocationListener_Coarse == null) { mLocationListener_Coarse = new LocationListener() { // LocationListener @Override public void onLocationChanged(Location location) { float currentLocationAccuracy = location.getAccuracy(); myLocationFixCnt_Coarse++; if ((myLocationFixCnt_Coarse >= Constants.kMaxGpsFixCnt) || ((location.hasAccuracy()) && (currentLocationAccuracy <= 1000.0))) // quick, // rough // location { // stop the coarse location service mLocationManager.removeUpdates(this); } updateMyLocation(location); } @Override public void onProviderDisabled(String provider) { Log.v(Constants.LOGTAG, "Provider Disabled: " + provider); } @Override public void onProviderEnabled(String provider) { Log.v(Constants.LOGTAG, "Provider Enabled: " + provider); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { Log.v(Constants.LOGTAG, "Provider Status Change: " + provider + " status:" + status); // LocationProvider.OUT_OF_SERVICE } }; } // still in registerLocationListeners // String provider = null; Criteria crta = new Criteria(); crta.setAccuracy(Criteria.ACCURACY_FINE); crta.setAltitudeRequired(false); crta.setBearingRequired(false); crta.setCostAllowed(false); // Indicates whether the provider is allowed // to incur monetary cost. // crta.setPowerRequirement(Criteria.POWER_MEDIUM); // POWER_LOW); provider = mLocationManager.getBestProvider(crta, true); // provider = LocationManager.NETWORK_PROVIDER; // get the last, possibly very wrong location currentLocation = mLocationManager.getLastKnownLocation(provider); // updateMyLocation(location); // minTime (2nd) the minimum time interval for notifications, in // milliseconds. This field is only used as a hint to conserve power, // and actual time between location updates may be greater or lesser // than this value. // minDistance (3rd)the minimum distance interval for notifications, in // meters // should be ~ 10000, 100 // mLocationManager.requestLocationUpdates(provider, 3000, 50, // mLocationListener_Fine); mLocationManager.requestLocationUpdates(provider, 3000, 0, mLocationListener_Fine); // Add second quick location provider Criteria coarse = new Criteria(); coarse.setAccuracy(Criteria.ACCURACY_COARSE); coarse.setAltitudeRequired(false); coarse.setBearingRequired(false); // coarse.setCostAllowed(false); // crta.setPowerRequirement(Criteria.POWER_MEDIUM); // POWER_LOW); String coarseProvider = mLocationManager.getBestProvider(coarse, true); if ((provider != null) && (!provider.contentEquals(coarseProvider))) { // only add coarse location resolution if DIFFERENT than the fine // location provider mLocationManager.requestLocationUpdates(coarseProvider, 1000, 1000, mLocationListener_Coarse); } }
From source file:de.vanita5.twittnuker.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. *//*w ww . j av a 2 s. 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) { 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); setProgressVisibility(true); } mRecentLocation = location != null ? new ParcelableLocation(location) : null; } else { Crouton.showText(this, R.string.cannot_get_location, CroutonStyle.ALERT); } return provider != null; }
From source file:com.google.ytd.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);/* w w w. ja v a2 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; double lat = location.getLatitude(); double 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: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. **/// w w 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) { 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:com.gmail.boiledorange73.ut.map.MapActivityBase.java
/** * Starts location services and timer to stop after specfied time. * /*from ww w . j a va2 s .c o m*/ * @see http://d.hatena.ne.jp/orangesignal/20101223/1293079002 */ private void startLocationService(boolean highaccuracy) { // this.stopLocationService(); this.mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (this.mLocationManager == null) { // this device has no location service. DOES NOTHING. return; } // gets active location providers. // if requires high accuracy, creates filtered provider list. List<String> providerList = this.mLocationManager.getProviders(true); if (highaccuracy) { ArrayList<String> candidateList = new ArrayList<String>(); if (providerList != null) { for (String providerName : providerList) { if (providerName != null) { LocationProvider provider = this.mLocationManager.getProvider(providerName); if (provider != null && provider.getAccuracy() == Criteria.ACCURACY_FINE) { candidateList.add(providerName); } } } } providerList = candidateList; } // checks whether at least one location provider is available. if (providerList == null || !(providerList.size() > 0)) { // Shows the dialog which let user to open system preference. AlertDialogHelper.showConfirmationDialog(this, Messages.getString("P_LOCATION_PROVIDER_ERROR"), Messages.getString("P_CONFIRM_OPEN_LOACTIONPROVIDER_SETTINGS"), android.R.drawable.ic_dialog_info, new DialogInterface.OnClickListener() { @Override public void onClick(final DialogInterface dialog, final int which) { try { startActivity(new Intent("android.settings.LOCATION_SOURCE_SETTINGS")); } catch (final ActivityNotFoundException e) { // DOES NOTHING e.printStackTrace(); } } }); this.stopLocationService(); return; } // Starts timer. Checks whether timed out frequently, // and stops location services when specified time comes. final boolean onlyPassive = (providerList.size() == 1 && "passive".equals(providerList.get(0))); this.mLocationTimer = new Timer(true); this.mTimedOut = System.currentTimeMillis() + 30000L; final Handler handler = new Handler(); this.mToast = Toast.makeText(this, Messages.getString("P_MYLOCATION_FINDING"), Toast.LENGTH_SHORT); this.mToast.show(); this.mLocationTimer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { // Sends the procedure checks whether timed out. handler.post(new Runnable() { @Override public void run() { long current = System.currentTimeMillis(); if (current >= MapActivityBase.this.mTimedOut) { // timed out. MapActivityBase.this.onLocationServiceTimedout(onlyPassive); } else { // NOT timed out. Shows the TOAST. MapActivityBase.this.mToast.show(); } } }); } }, 0L, 1000L); // starts this.mLocationListener = new LocationListener() { @Override public void onLocationChanged(final Location location) { // New location got. Sends it to JS. setLocation(location, true); } @Override public void onProviderDisabled(final String provider) { // DOES NOTHING. } @Override public void onProviderEnabled(final String provider) { // DOES NOTHING. } @Override public void onStatusChanged(final String provider, final int status, final Bundle extras) { // DOES NOTHING. } }; for (String provider : providerList) { this.mLocationManager.requestLocationUpdates(provider, 0, 0, this.mLocationListener); } }