List of usage examples for android.location Criteria Criteria
public Criteria()
From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java
public boolean drawUserDestRoute(LatLng destination) { gmm.handleMapWarningMessages(POIMapActivity.this, tvMapMessage); if (!gmm.myLocationEnabled || !gmm.internetEnabled) { tvMapMessage.setBackgroundColor(POIMapActivity.this.getResources().getColor(R.color.red_transparent)); miDirections.setIcon(R.drawable.ic_action_directions); mActionDirections = 0;//from w w w.j ava 2 s. c o m tvMapDirectionsInfo.setVisibility(View.INVISIBLE); } else { if (gmm.googleMap.getMyLocation() != null) { userLocation = new LatLng(gmm.googleMap.getMyLocation().getLatitude(), gmm.googleMap.getMyLocation().getLongitude()); } else { LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = service.getBestProvider(criteria, false); Location location = service.getLastKnownLocation(provider); if (location != null) { userLocation = new LatLng(location.getLatitude(), location.getLongitude()); } else { Toast.makeText(POIMapActivity.this, POIMapActivity.this.getResources().getString(R.string.my_location_problem), Toast.LENGTH_LONG).show(); return false; } } new connectAsyncTask(gmm.makeURL(userLocation.latitude, userLocation.longitude, destination.latitude, destination.longitude)).execute(); } return true; }
From source file:com.dragon4.owo.ar_trace.ARCore.MixView.java
@Override protected void onResume() { super.onResume(); try {/*from www . ja v a 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:org.otempo.view.StationActivity.java
/** * Inicializa la estacin elegida, mirando en el GPS y sino pillando la primera. *///from w w w . j a v a 2 s. co m private void initStationManager() { final Object data = getLastNonConfigurationInstance(); if (data == null) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); String defaultStationPreference = prefs.getString(Preferences.PREF_DEFAULT_STATION, Preferences.DEFAULT_DEFAULT_STATION); int defaultStationFixed = Integer.valueOf(prefs.getString(Preferences.PREF_DEFAULT_STATION_FIXED, "1")); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); assert locationManager != null; _stationManager = new StationManager(locationManager, defaultStationPreference, defaultStationFixed); if (locationManager.getBestProvider(new Criteria(), false) == null) { Toast.makeText(getApplicationContext(), R.string.gps_unavailable, Toast.LENGTH_LONG).show(); } } else { final Object[] list = (Object[]) data; _stationManager = (StationManager) list[0]; _skipDialog = true; } _stationManager.setListener(this); }
From source file:com.ht.app.RestaurantsActivity.java
private Location getLastKnownLocation() { LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); String provider = lm.getBestProvider(criteria, true); if (provider == null) { return null; }/*from w ww . ja v a 2 s . c o m*/ return lm.getLastKnownLocation(provider); }
From source file:com.seatgeek.placesautocompletedemo.MainFragment.java
private LatLng getLastKnownLocation(boolean isMoveMarker) { LocationManager lm = (LocationManager) TheApp.getAppContext().getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_LOW); String provider = lm.getBestProvider(criteria, true); if (provider == null) { return null; }//w ww.j a va 2s. c om Activity activity = getActivity(); if (activity == null) { return null; } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { if (activity.checkSelfPermission( Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && activity.checkSelfPermission( Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return null; } } Location loc = lm.getLastKnownLocation(provider); if (loc != null) { LatLng latLng = new LatLng(loc.getLatitude(), loc.getLongitude()); if (isMoveMarker) { moveMarker(latLng); } return latLng; } return null; }
From source file:pandroid.agent.PandroidAgentListener.java
private void gpsLocation() { // Starts with GPS, if no GPS then gets network location // /*from w w w . j a v a 2 s .co m*/ LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(true); Log.d("PANDROID providers count", "" + providers.size()); /* Loop over the array backwards, and if you get an accurate location, then break out the loop*/ Location loc = null; for (int i = providers.size() - 1; i >= 0; i--) { Log.d("PANDROID providers", providers.get(i)); loc = lm.getLastKnownLocation(providers.get(i)); if (loc != null) break; } if (loc != null) { Log.d("PANDROID", "loc != null"); //if(latitude != loc.getLatitude() || longitude != loc.getLongitude()) { lastGpsContactDateTime = getHumanDateTime(-1); //`} Log.d("LATITUDE", Double.valueOf(loc.getLatitude()).toString()); Log.d("LONGITUDE", Double.valueOf(loc.getLongitude()).toString()); putSharedData("PANDROID_DATA", "latitude", Double.valueOf(loc.getLatitude()).toString(), "float"); putSharedData("PANDROID_DATA", "longitude", Double.valueOf(loc.getLongitude()).toString(), "float"); } Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); String bestProvider = lm.getBestProvider(criteria, true); // If not provider found, abort GPS retrieving if (bestProvider == null) { Log.e("LOCATION", "No location provider found!"); return; } lm.requestLocationUpdates(bestProvider, Core.interval, 15, new LocationListener() { public void onLocationChanged(Location location) { Log.d("Best latitude", Double.valueOf(location.getLatitude()).toString()); putSharedData("PANDROID_DATA", "latitude", Double.valueOf(location.getLatitude()).toString(), "float"); Log.d("Best longitude", Double.valueOf(location.getLongitude()).toString()); putSharedData("PANDROID_DATA", "longitude", Double.valueOf(location.getLongitude()).toString(), "float"); } public void onStatusChanged(String s, int i, Bundle bundle) { } public void onProviderEnabled(String s) { // try switching to a different provider } public void onProviderDisabled(String s) { putSharedData("PANDROID_DATA", "enabled_location_provider", "disabled", "string"); } }); //} }
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// w w w . j a v a 2 s.co 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. *//*from ww w .j ava 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.example.angel.parkpanda.MainActivity.java
private Location MMgetMyLocation() { LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = service.getBestProvider(criteria, false); if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling // ActivityCompat#requestPermissions // here to request the missing permissions, and then overriding // public void onRequestPermissionsResult(int requestCode, String[] permissions, // int[] grantResults) // to handle the case where the user grants the permission. See the documentation // for ActivityCompat#requestPermissions for more details. }/*from w w w.ja v a 2s .c o m*/ Location location = service.getLastKnownLocation(provider); return location; }
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);/*from w w w . j a 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); } }