List of usage examples for android.location Criteria Criteria
public Criteria()
From source file:com.example.david.wheretogo_test1.PickerActivity.java
@Override protected void onStart() { super.onStart(); if (FRIEND_PICKER.equals(getIntent().getData())) { try {/*from w w w .j a v a 2s. c o m*/ friendPickerFragment.loadData(false); } catch (Exception ex) { onError(ex); } } else if (PLACE_PICKER.equals(getIntent().getData())) { try { Location location = null; Criteria criteria = new Criteria(); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); String bestProvider = locationManager.getBestProvider(criteria, false); if (bestProvider != null) { location = locationManager.getLastKnownLocation(bestProvider); if (locationManager.isProviderEnabled(bestProvider) && locationListener == null) { locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { boolean updateLocation = true; Location prevLocation = placePickerFragment.getLocation(); if (prevLocation != null) { updateLocation = location.distanceTo(prevLocation) >= LOCATION_CHANGE_THRESHOLD; } if (updateLocation) { placePickerFragment.setLocation(location); placePickerFragment.loadData(true); } } @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { } @Override public void onProviderDisabled(String s) { } }; locationManager.requestLocationUpdates(bestProvider, 1, LOCATION_CHANGE_THRESHOLD, locationListener, Looper.getMainLooper()); } } if (location == null) { String model = Build.MODEL; if (model.equals("sdk") || model.equals("google_sdk") || model.contains("x86")) { // this may be the emulator, pretend we're in an exotic place location = SAN_FRANCISCO_LOCATION; } } if (location != null) { placePickerFragment.setLocation(location); placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS); placePickerFragment.setSearchText(SEARCH_TEXT); placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT); placePickerFragment.loadData(false); } else { onError(getResources().getString(R.string.no_location_error), true); } } catch (Exception ex) { onError(ex); } } }
From source file:com.android.transmart.PlaceActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inflate the layout setContentView(R.layout.nearby);//from w w w .j a va2 s . c o m // Get a handle to the Fragments placeListFragment = (PlaceListFragment) getSupportFragmentManager().findFragmentById(R.id.list_fragment); checkinFragment = (CheckinFragment) getSupportFragmentManager().findFragmentById(R.id.checkin_fragment); // Get references to the managers packageManager = getPackageManager(); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Get a reference to the Shared Preferences and a Shared Preference Editor. prefs = getSharedPreferences(LocationConstants.SHARED_PREFERENCE_FILE, Context.MODE_PRIVATE); prefsEditor = prefs.edit(); // Instantiate a SharedPreferenceSaver class based on the available platform version. // This will be used to save shared preferences sharedPreferenceSaver = PlatformSpecific.getSharedPreferenceSaver(this); // Save that we've been run once. prefsEditor.putBoolean(LocationConstants.SP_KEY_RUN_ONCE, true); sharedPreferenceSaver.savePreferences(prefsEditor, false); // Specify the Criteria to use when requesting location updates while the application is Active criteria = new Criteria(); if (LocationConstants.USE_GPS_WHEN_ACTIVITY_VISIBLE) criteria.setAccuracy(Criteria.ACCURACY_FINE); else criteria.setPowerRequirement(Criteria.POWER_LOW); // Setup the location update Pending Intents Intent activeIntent = new Intent(this, LocationChangedReceiver.class); locationListenerPendingIntent = PendingIntent.getBroadcast(this, 0, activeIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent passiveIntent = new Intent(this, PassiveLocReceiver.class); locationListenerPassivePendingIntent = PendingIntent.getBroadcast(this, 0, passiveIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Instantiate a LastLocationFinder class. // This will be used to find the last known location when the application starts. lastLocationFinder = PlatformSpecific.getLastLocationFinder(this); lastLocationFinder.setChangedLocationListener(oneShotLastLocationUpdateListener); // Instantiate a Location Update Requester class based on the available platform version. // This will be used to request location updates. locationUpdateRequester = PlatformSpecific.getLocationUpdateRequester(locationManager); // Create an Intent Filter to listen for checkins newCheckinReceiverName = new ComponentName(this, NewCheckinReceiver.class); newCheckinFilter = new IntentFilter(LocationConstants.NEW_CHECKIN_ACTION); // Check to see if an Place ID has been specified in the launch Intent. // If so, we should display the details for the specified venue. if (getIntent().hasExtra(LocationConstants.EXTRA_KEY_ID)) { Intent intent = getIntent(); String key = intent.getStringExtra(LocationConstants.EXTRA_KEY_ID); if (key != null) { selectDetail(null, key); // Remove the ID from the Intent (so that a resume doesn't reselect). intent.removeExtra(LocationConstants.EXTRA_KEY_ID); setIntent(intent); } } }
From source file:com.fpil.android.remotesensor.MainDisplay.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); Criteria locationCriteria = new Criteria(); locationCriteria.setAccuracy(Criteria.ACCURACY_FINE); locationCriteria.setAltitudeRequired(false); locationCriteria.setBearingRequired(false); locationCriteria.setCostAllowed(true); locationCriteria.setPowerRequirement(Criteria.NO_REQUIREMENT); locationProviderName = locationManager.getBestProvider(locationCriteria, true); if (ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Toast.makeText(getActivity(), R.string.turn_on_gps, Toast.LENGTH_LONG).show(); Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); this.startActivity(myIntent); }/*w ww. jav a 2 s . c o m*/ if (locationProviderName != null && locationManager.isProviderEnabled(locationProviderName)) { // Provider is enabled Toast.makeText(getActivity(), R.string.gps_available, Toast.LENGTH_LONG).show(); } else { // Provider not enabled, prompt user to enable it Toast.makeText(getActivity(), R.string.turn_on_gps, Toast.LENGTH_LONG).show(); Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); this.startActivity(myIntent); } }
From source file:com.chalmers.schmaps.CheckInActivity.java
/** * assigns variables used in this class//w w w . ja va2 s . co m */ public void assignInstances() { setContentView(R.layout.activity_checkin); returnedJsonObject = null; username = ""; checkin = false; running = false; mapview = (MapView) findViewById(R.id.mapview); mapview.setBuiltInZoomControls(true); mapcon = mapview.getController(); locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); //deafult criteria criteria = new Criteria(); //best reception bestProvider = locationManager.getBestProvider(criteria, false); //gets last known location from chosen provider location = locationManager.getLastKnownLocation(bestProvider); Button checkInButton; checkInButton = (Button) findViewById(R.id.checkinbutton); enterName = (EditText) findViewById(R.id.entername); checkInButton.setOnClickListener(this); }
From source file:com.riverspart.location.ui.PlaceActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Inflate the layout setContentView(R.layout.location_main); // Get a handle to the Fragments placeListFragment = (PlaceListFragment) getSupportFragmentManager().findFragmentById(R.id.list_fragment); checkinFragment = (CheckinFragment) getSupportFragmentManager().findFragmentById(R.id.checkin_fragment); // Get references to the managers packageManager = getPackageManager(); notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Get a reference to the Shared Preferences and a Shared Preference Editor. prefs = getSharedPreferences(PlacesConstants.SHARED_PREFERENCE_FILE, Context.MODE_PRIVATE); prefsEditor = prefs.edit();// w ww. j a v a2 s. c om // Instantiate a SharedPreferenceSaver class based on the available platform version. // This will be used to save shared preferences sharedPreferenceSaver = PlatformSpecificImplementationFactory.getSharedPreferenceSaver(this); // Save that we've been run once. prefsEditor.putBoolean(PlacesConstants.SP_KEY_RUN_ONCE, true); sharedPreferenceSaver.savePreferences(prefsEditor, false); // Specify the Criteria to use when requesting location updates while the application is Active criteria = new Criteria(); if (PlacesConstants.USE_GPS_WHEN_ACTIVITY_VISIBLE) criteria.setAccuracy(Criteria.ACCURACY_FINE); else criteria.setPowerRequirement(Criteria.POWER_LOW); // Setup the location update Pending Intents Intent activeIntent = new Intent(this, LocationChangedReceiver.class); locationListenerPendingIntent = PendingIntent.getBroadcast(this, 0, activeIntent, PendingIntent.FLAG_UPDATE_CURRENT); Intent passiveIntent = new Intent(this, PassiveLocationChangedReceiver.class); locationListenerPassivePendingIntent = PendingIntent.getBroadcast(this, 0, passiveIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Instantiate a LastLocationFinder class. // This will be used to find the last known location when the application starts. lastLocationFinder = PlatformSpecificImplementationFactory.getLastLocationFinder(this); lastLocationFinder.setChangedLocationListener(oneShotLastLocationUpdateListener); // Instantiate a Location Update Requester class based on the available platform version. // This will be used to request location updates. locationUpdateRequester = PlatformSpecificImplementationFactory.getLocationUpdateRequester(locationManager); // Create an Intent Filter to listen for checkins newCheckinReceiverName = new ComponentName(this, NewCheckinReceiver.class); newCheckinFilter = new IntentFilter(PlacesConstants.NEW_CHECKIN_ACTION); // Check to see if an Place ID has been specified in the launch Intent. // If so, we should display the details for the specified venue. if (getIntent().hasExtra(PlacesConstants.EXTRA_KEY_ID)) { Intent intent = getIntent(); String key = intent.getStringExtra(PlacesConstants.EXTRA_KEY_ID); if (key != null) { selectDetail(null, key); // Remove the ID from the Intent (so that a resume doesn't reselect). intent.removeExtra(PlacesConstants.EXTRA_KEY_ID); setIntent(intent); } } }
From source file:br.com.split.activities.FacebookEscolherLocalActivity.java
private void onClickGPS() { try {//from w w w. j av a 2s . c om if (lastKnownLocation == null) { Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, false); if (bestProvider != null) { lastKnownLocation = locationManager.getLastKnownLocation(bestProvider); } } if (lastKnownLocation == null) { String model = android.os.Build.MODEL; if (model.equals("sdk") || model.equals("google_sdk") || model.contains("x86")) { // Looks like they are on an emulator, pretend we're in Paris if we don't have a // location set. lastKnownLocation = PORTO_ALEGRE_LOCATION; } else { //onError(new Exception(getString(R.string.erro_sem_localizacao))); //return; lastKnownLocation = PORTO_ALEGRE_LOCATION; } } startPickPlaceActivity(lastKnownLocation); } catch (Exception ex) { onError(ex); } }
From source file:org.notfunnynerd.opencoinmap.MapActivity.java
private void initLocation() { // Get the location manager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); boolean enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (!enabled) { Toast.makeText(this, getString(R.string.enable_location_service), Toast.LENGTH_LONG).show(); }//w ww . ja v a 2s.c o m Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, false); }
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;/*w ww . j av a 2s.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.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:com.example.scrumptious.PickerActivity.java
@Override protected void onStart() { super.onStart(); if (FRIEND_PICKER.equals(getIntent().getData())) { try {/*from w w w . j a v a 2s .c o m*/ friendPickerFragment.loadData(false); } catch (Exception ex) { onError(ex); } } else if (PLACE_PICKER.equals(getIntent().getData())) { try { Location location = null; Criteria criteria = new Criteria(); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); String bestProvider = locationManager.getBestProvider(criteria, false); if (bestProvider != null) { location = locationManager.getLastKnownLocation(bestProvider); if (locationManager.isProviderEnabled(bestProvider) && locationListener == null) { locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { boolean updateLocation = true; Location prevLocation = placePickerFragment.getLocation(); if (prevLocation != null) { updateLocation = location.distanceTo(prevLocation) >= LOCATION_CHANGE_THRESHOLD; } if (updateLocation) { placePickerFragment.setLocation(location); placePickerFragment.loadData(true); } } @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { } @Override public void onProviderDisabled(String s) { } }; locationManager.requestLocationUpdates(bestProvider, 1, LOCATION_CHANGE_THRESHOLD, locationListener, Looper.getMainLooper()); } } if (location != null) { placePickerFragment.setLocation(location); placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS); placePickerFragment.setSearchText(SEARCH_TEXT); placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT); placePickerFragment.loadData(false); } } catch (Exception ex) { onError(ex); } } }