List of usage examples for android.location Criteria ACCURACY_COARSE
int ACCURACY_COARSE
To view the source code for android.location Criteria ACCURACY_COARSE.
Click Source Link
From source file:com.xmobileapp.rockplayer.LastFmEventImporter.java
/********************************* * /*from ww w . ja v a2s. com*/ * Constructor * @param context * *********************************/ public LastFmEventImporter(Context context) { this.context = context; Log.i("LASTFMEVENT", "creating-------------------------"); /* * Check for Internet Connection (Through whichever interface) */ ConnectivityManager connManager = (ConnectivityManager) ((RockPlayer) context) .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = connManager.getActiveNetworkInfo(); /******* EMULATOR HACK - false condition needs to be removed *****/ //if (false && (netInfo == null || !netInfo.isConnected())){ if ((netInfo == null || !netInfo.isConnected())) { Bundle data = new Bundle(); data.putString("info", "No Internet Connection"); Message msg = new Message(); msg.setData(data); ((RockPlayer) context).analyseConcertInfoHandler.sendMessage(msg); return; } /* * Get location */ MIN_UPDATE_INTVL = 5 * 24 * 60 * 60 * 1000; // 5 days SPREAD_INTVL = 21 * 24 * 60 * 60 * 1000; // 21 days; Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); LocationManager locManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (locManager.getBestProvider(criteria, true) != null) myLocation = locManager.getLastKnownLocation(locManager.getBestProvider(criteria, true)); else { myLocation = new Location("gps"); myLocation.setLatitude(47.100301); myLocation.setLongitude(-119.982465); } /* * Get preferred distance */ // SharedPreferences prefs = ((Filex) context).getSharedPreferences(((Filex) context).PREFS_NAME, 0); RockOnPreferenceManager prefs = new RockOnPreferenceManager(((RockPlayer) context).FILEX_PREFERENCES_PATH); concertRadius = prefs.getLong("ConcertRadius", (long) (((RockPlayer) context).CONCERT_RADIUS_DEFAULT)); //myLocation = locManager.getLastKnownLocation(locManager.getBestProvider(Criteria.POWER_LOW, true)); // try { // getArtistEvents(); // } catch (SAXException e) { // e.printStackTrace(); // } catch (ParserConfigurationException e) { // e.printStackTrace(); // } }
From source file:org.navitproject.navit.NavitVehicle.java
/** * @brief Creates a new {@code NavitVehicle} * * @param context/*w w w.j a v a2s . c o m*/ * @param pcbid The address of the position callback function called when a location update is received * @param scbid The address of the status callback function called when a status update is received * @param fcbid The address of the fix callback function called when a * {@code android.location.GPS_FIX_CHANGE} is received, indicating a change in GPS fix status */ NavitVehicle(Context context, int pcbid, int scbid, int fcbid) { if (ContextCompat.checkSelfPermission(context, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // Permission is not granted return; } this.context = context; sLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); preciseLocationListener = new NavitLocationListener(); preciseLocationListener.precise = true; fastLocationListener = new NavitLocationListener(); /* Use 2 LocationProviders, one precise (usually GPS), and one not so precise, but possible faster. The fast provider is disabled when the precise provider gets its first fix. */ // Selection criteria for the precise provider Criteria highCriteria = new Criteria(); highCriteria.setAccuracy(Criteria.ACCURACY_FINE); highCriteria.setAltitudeRequired(true); highCriteria.setBearingRequired(true); highCriteria.setCostAllowed(true); highCriteria.setPowerRequirement(Criteria.POWER_HIGH); // Selection criteria for the fast provider Criteria lowCriteria = new Criteria(); lowCriteria.setAccuracy(Criteria.ACCURACY_COARSE); lowCriteria.setAltitudeRequired(false); lowCriteria.setBearingRequired(false); lowCriteria.setCostAllowed(true); lowCriteria.setPowerRequirement(Criteria.POWER_HIGH); Log.e("NavitVehicle", "Providers " + sLocationManager.getAllProviders()); preciseProvider = sLocationManager.getBestProvider(highCriteria, false); Log.e("NavitVehicle", "Precise Provider " + preciseProvider); fastProvider = sLocationManager.getBestProvider(lowCriteria, false); Log.e("NavitVehicle", "Fast Provider " + fastProvider); vehicle_pcbid = pcbid; vehicle_scbid = scbid; vehicle_fcbid = fcbid; context.registerReceiver(preciseLocationListener, new IntentFilter(GPS_FIX_CHANGE)); sLocationManager.requestLocationUpdates(preciseProvider, 0, 0, preciseLocationListener); sLocationManager.addGpsStatusListener(preciseLocationListener); /* * Since Android criteria have no way to specify "fast fix", lowCriteria may return the same * provider as highCriteria, even if others are available. In this case, do not register two * listeners for the same provider but pick the fast provider manually. (Usually there will * only be two providers in total, which makes the choice easy.) */ if (fastProvider == null || preciseProvider.compareTo(fastProvider) == 0) { List<String> fastProviderList = sLocationManager.getProviders(lowCriteria, false); fastProvider = null; for (String fastCandidate : fastProviderList) { if (preciseProvider.compareTo(fastCandidate) != 0) { fastProvider = fastCandidate; break; } } } if (fastProvider != null) { sLocationManager.requestLocationUpdates(fastProvider, 0, 0, fastLocationListener); } }
From source file:com.intel.xdk.geolocation.Geolocation.java
private String getBestProvider(boolean highAccuracy) { Criteria c = new Criteria(); c.setAccuracy(highAccuracy ? Criteria.ACCURACY_FINE : Criteria.ACCURACY_COARSE); String provider = locMan.getBestProvider(c, true); //System.out.println("getBestProvider: " + provider); return provider; }
From source file:net.digitalphantom.app.weatherapp.WeatherActivity.java
private void getWeatherFromCurrentLocation() { if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION, }, GET_WEATHER_FROM_CURRENT_LOCATION); return;/*from w ww . jav a 2 s. c o m*/ } // system's LocationManager final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); boolean isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); boolean isGPSEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); Criteria locationCriteria = new Criteria(); if (isNetworkEnabled) { locationCriteria.setAccuracy(Criteria.ACCURACY_COARSE); } else if (isGPSEnabled) { locationCriteria.setAccuracy(Criteria.ACCURACY_FINE); } locationManager.requestSingleUpdate(locationCriteria, this, null); }
From source file:com.johan.vertretungsplan_2.SelectSchoolActivity.java
private void showListGeo() { final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); // no GPS final String provider = locationManager.getBestProvider(criteria, true); if (provider == null) { Log.d("vertretungsplan", "provider==null"); tvLocateString.setText(R.string.geolocate_disabled); status = Status.LIST;/*from w w w .j av a2 s . c o m*/ return; } locationManager.requestLocationUpdates(provider, 0, 0, new LocationListener() { @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } @Override public void onLocationChanged(Location location) { if (!visible) return; if (location != null) { double lat = location.getLatitude(); double lon = location.getLongitude(); for (Schule school : schools) { float[] result = new float[1]; Location.distanceBetween(lat, lon, school.getGeo()[0], school.getGeo()[1], result); school.setDistance(result[0]); Log.d("vertretungsplan", school.getName() + ": " + school.getDistance()); } Collections.sort(schools, new DistanceSchoolComparator()); lstSchools.setAdapter(new SchoolsAdapter(SelectSchoolActivity.this, schools, true)); } tvLocateString.setText(R.string.alphabetic_list); ivLocationIcon.setImageResource(R.drawable.ic_action_view_as_list); status = Status.GEO; } }); }
From source file:org.microg.gms.maps.GoogleMapImpl.java
private GoogleMapImpl(Context context, GoogleMapOptions options) { this.context = context; Context appContext = context; if (appContext.getApplicationContext() != null) appContext = appContext.getApplicationContext(); Context wrappedContext = ApplicationContextWrapper.gmsContextWithAttachedApplicationContext(appContext); backendMap = new BackendMap(wrappedContext, this); uiSettings = new UiSettingsImpl(this); projection = new ProjectionImpl(backendMap.getViewport()); this.options = options; criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_MEDIUM); if (options != null) initFromOptions();//from w w w . j ava2s. c o m }
From source file:ch.hesso.master.sweetcity.activity.map.MapActivity.java
public void showCurrentPosition() { if (map == null) return;/*from w ww.j a v a2 s. c om*/ // Enabling MyLocation Layer of Google Map map.setMyLocationEnabled(true); Criteria lightCriteria = new Criteria(); lightCriteria.setAccuracy(Criteria.ACCURACY_COARSE); lightCriteria.setAltitudeRequired(false); lightCriteria.setBearingRequired(false); lightCriteria.setCostAllowed(false); lightCriteria.setHorizontalAccuracy(Criteria.ACCURACY_MEDIUM); lightCriteria.setPowerRequirement(Criteria.NO_REQUIREMENT); lightCriteria.setSpeedAccuracy(Criteria.NO_REQUIREMENT); lightCriteria.setSpeedRequired(false); listener = new MapLocationListener(map); locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); locationManager.requestSingleUpdate(lightCriteria, listener, null); locationProvider = locationManager.getBestProvider(new Criteria(), true); Location location = locationManager.getLastKnownLocation(locationProvider); if (location != null) { listener.onLocationChanged(location); map.animateCamera(CameraUpdateFactory.zoomTo(15)); } }
From source file:org.wso2.edgeanalyticsservice.LocationSystemService.java
/** Initialize the location system Service and set the minimal update distance and time */ public void startLocationService(Context context) { mContext = context;/*from w w w .j av a 2s . co m*/ mLocationManager = (LocationManager) mContext.getSystemService(mContext.LOCATION_SERVICE); Criteria locationCritera = new Criteria(); locationCritera.setAccuracy(Criteria.ACCURACY_COARSE); locationCritera.setAltitudeRequired(false); locationCritera.setBearingRequired(false); locationCritera.setCostAllowed(true); locationCritera.setPowerRequirement(Criteria.NO_REQUIREMENT); String providerName = mLocationManager.getBestProvider(locationCritera, true); if (providerName != null && mLocationManager.isProviderEnabled(providerName)) { if (ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(mContext, 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. Log.e("Location", "No permission"); return; } mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, (float) MINIMUM_DISTANCE_FOR_UPDATES, new MyLocationListner(), Looper.getMainLooper()); mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MINIMUM_TIME_BETWEEN_UPDATES, (float) MINIMUM_DISTANCE_FOR_UPDATES, new MyLocationListner(), Looper.getMainLooper()); mlocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); // mTaskManager.sendLocationData(new double[]{mlocation.getLatitude(), mlocation.getLongitude()}); mLocationListner = new MyLocationListner(); synchronized (this) { started = true; } } else { // Provider not enabled, prompt user to enable it Toast.makeText(mContext, "Please turn on GPS", Toast.LENGTH_LONG).show(); Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); mContext.startActivity(myIntent); } }
From source file:de.madvertise.android.sdk.MadUtil.java
/** * Try to update current location. Non blocking call. * // ww w . j a va2 s .com * @param context * application context */ protected static void refreshCoordinates(Context context) { if (PRINT_LOG) Log.d(LOG, "Trying to refresh location"); if (context == null) { if (PRINT_LOG) Log.d(LOG, "Context not set - quit location refresh"); return; } // check if we need a regular update if ((locationUpdateTimestamp + MadUtil.SECONDS_TO_REFRESH_LOCATION * 1000) > System.currentTimeMillis()) { if (PRINT_LOG) Log.d(LOG, "It's not time yet for refreshing the location"); return; } synchronized (context) { // recheck, if location was updated by another thread while we paused if ((locationUpdateTimestamp + MadUtil.SECONDS_TO_REFRESH_LOCATION * 1000) > System .currentTimeMillis()) { if (PRINT_LOG) Log.d(LOG, "Another thread updated the loation already"); return; } boolean permissionCoarseLocation = context.checkCallingOrSelfPermission( android.Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED; boolean permissionFineLocation = context.checkCallingOrSelfPermission( android.Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED; // return (null) if we do not have any permissions if (!permissionCoarseLocation && !permissionFineLocation) { if (PRINT_LOG) Log.d(LOG, "No permissions for requesting the location"); return; } // return (null) if we can't get a location manager LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); if (locationManager == null) { if (PRINT_LOG) Log.d(LOG, "Unable to fetch a location manger"); return; } String provider = null; Criteria criteria = new Criteria(); criteria.setCostAllowed(false); // try to get coarse location first if (permissionCoarseLocation) { criteria.setAccuracy(Criteria.ACCURACY_COARSE); provider = locationManager.getBestProvider(criteria, true); } // try to get gps location if coarse locatio did not work if (provider == null && permissionFineLocation) { criteria.setAccuracy(Criteria.ACCURACY_FINE); provider = locationManager.getBestProvider(criteria, true); } // still no provider, return (null) if (provider == null) { if (PRINT_LOG) Log.d(LOG, "Unable to fetch a location provider"); return; } // create a finalized reference to the location manager, in order to // access it in the inner class final LocationManager finalizedLocationManager = locationManager; locationUpdateTimestamp = System.currentTimeMillis(); locationManager.requestLocationUpdates(provider, 0, 0, new LocationListener() { public void onLocationChanged(Location location) { if (PRINT_LOG) Log.d(LOG, "Refreshing location"); currentLocation = location; locationUpdateTimestamp = System.currentTimeMillis(); // stop draining battery life finalizedLocationManager.removeUpdates(this); } // not used yet public void onProviderDisabled(String provider) { } public void onProviderEnabled(String provider) { } public void onStatusChanged(String provider, int status, Bundle extras) { } }, context.getMainLooper()); } }
From source file:org.deviceconnect.android.deviceplugin.host.profile.HostGeolocationProfile.java
/** * ?????./* w w w. j a v a2s. com*/ * @param accuracy . * @param response ?. */ private void getGPS(final boolean accuracy, final Intent response) { if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getContext(), ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { MessageUtils.setIllegalDeviceStateError(response, "ACCESS_FINE_LOCATION permission not granted."); sendResponse(response); return; } Criteria criteria = new Criteria(); if (accuracy) { criteria.setAccuracy(Criteria.ACCURACY_FINE); } else { criteria.setAccuracy(Criteria.ACCURACY_COARSE); } mLocationManager.requestSingleUpdate(mLocationManager.getBestProvider(criteria, true), new LocationListener() { @Override public void onLocationChanged(Location location) { Bundle position = createPositionObject(location); DConnectProfile.setResult(response, DConnectMessage.RESULT_OK); response.putExtra(GeolocationProfile.PARAM_POSITION, position); sendResponse(response); } @Override public void onStatusChanged(String provider, int status, Bundle extras) { // NOP } @Override public void onProviderEnabled(String provider) { // NOP } @Override public void onProviderDisabled(String provider) { // NOP } }, Looper.getMainLooper()); }