List of usage examples for android.location Criteria Criteria
public Criteria()
From source file:com.airbop.library.simple.CommonUtilities.java
/** * Simple helper that gets the location criteria that we want. * @return/*from w w w . j av a2 s. co m*/ */ public static Criteria getCriteria() { if (true) { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(false); criteria.setCostAllowed(true); return criteria; } return null; }
From source file:com.hqas.ridetracker.RideTrackerFragment.java
@Override public void onResume() { super.onResume(); locMan = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); Criteria crit = new Criteria(); crit.setAccuracy(Criteria.ACCURACY_FINE); locMan.requestLocationUpdates(0L, 0.0f, crit, tService, null); map.setLocationSource(tService);/*from www . j av a 2s. c o m*/ broadcastManager = LocalBroadcastManager.getInstance(getActivity()); broadcastManager.registerReceiver(mapUpdateReceiver, new IntentFilter(TrackerService.ACTION_MAP_UPDATE_LOCATION)); broadcastManager.registerReceiver(startStopReceiver, new IntentFilter(TrackerService.ACTION_START_STOP_RECEIVED)); broadcastManager.registerReceiver(pebbleConnectedReceiver, new IntentFilter(TrackerService.ACTION_PEBBLE_CONNECTED)); broadcastManager.registerReceiver(pebbleConnectedReceiver, new IntentFilter(TrackerService.ACTION_PEBBLE_DISCONNECTED)); broadcastManager.registerReceiver(resetReceiver, new IntentFilter(TrackerService.ACTION_RESET_RECEIVED)); if (PebbleKit.isWatchConnected(getActivity())) { PebbleKit.startAppOnPebble(getActivity(), MainActivity.PEBBLE_APP_UUID); pebbleConnected(); } else { pebbleStatus.setText(res.getString(R.string.pebble_status_disconnected)); pebbleDisconnected(); } }
From source file:com.wikitude.example.ARBrowserActivity.java
/** Called when the activity is first created. */ @Override//from w ww . j a va 2 s . c o m public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // let the application be fullscreen this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // check if the device fulfills the SDK'S minimum requirements if (!ArchitectView.isDeviceSupported(this)) { Toast.makeText(this, "minimum requirements not fulfilled", Toast.LENGTH_LONG).show(); this.finish(); return; } setContentView(R.layout.main); // set the devices' volume control to music to be able to change the // volume of possible soundfiles to play this.setVolumeControlStream(AudioManager.STREAM_MUSIC); this.architectView = (ArchitectView) this.findViewById(R.id.architectView); // onCreate method for setting the license key for the SDK architectView.onCreate(apiKey); // in order to inform the ARchitect framework about the user's location // Androids LocationManager is used in this case // NOT USED IN THIS EXAMPLE // locManager = // (LocationManager)getSystemService(Context.LOCATION_SERVICE); // locManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, // 0, this); // Getting LocationManager object from System Service LOCATION_SERVICE LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); // Creating a criteria object to retrieve provider Criteria criteria = new Criteria(); // Getting the name of the best provider String provider = locationManager.getBestProvider(criteria, true); // Getting Current Location Location location = locationManager.getLastKnownLocation(provider); locationManager.requestLocationUpdates(provider, 20000, 0, this); // Getting latitude of the current location fLat = location.getLatitude(); // Getting longitude of the current location fLng = location.getLongitude(); }
From source file:com.finlay.geomonsters.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { Log.v(TAG, "onCreated"); super.onCreate(savedInstanceState); _activity = this; // set app to fullscreen requestWindowFeature(Window.FEATURE_NO_TITLE); // layout/*from www . j a v a2 s. com*/ setContentView(R.layout.activity_ranch); // Socket, Location Manager, Weather Manager locationListener = new MyLocationListener(this); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); socket = new SocketIO(); weatherManager = new WeatherManager(this); // layout items theTextView = (TextView) findViewById(R.id.txtMessage); forceButton = (Button) findViewById(R.id.btnGetLocation); waitButton = (Button) findViewById(R.id.btnWaitLocation); loadEncounterButton = (Button) findViewById(R.id.btnLoadEncounter); // TODO get rid of this. For now, reset the encounters file whenever created ConfigManager.ResetConfigFiles(getApplicationContext()); forceButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Log.v(TAG, "Force Click"); // Ensure connected if (!isNetworkAvailable()) { setMessage("No internet connection."); return; } forceButton.setText("..."); // Connect to server connectSocket(); // Best provider Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, false); // Request location updates locationManager.requestLocationUpdates(bestProvider, 10000, 0, locationListener); forceButton.setEnabled(false); loadEncounterButton.setEnabled(false); } }); waitButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Log.v(TAG, "Wait click"); waitButton.setText("..."); // Start Encounter Service // TODO Service should be started at boot? _activity.startService(new Intent(_activity, EncounterService.class)); waitButton.setEnabled(false); } }); loadEncounterButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { Log.v(TAG, "Load encounter clicked"); // Ensure connection if (!isNetworkAvailable()) { setMessage("No internet connection."); return; } // Pull encounter String encounter = ConfigManager.PullEncounter(getApplicationContext()); if (encounter.equals("")) return; // Use location & time from gathered string to query encounter String[] location = encounter.split(","); String latitude = location[0]; String longitude = location[1]; // TODO We cannot get historical weatherdata accurately. So we will just use the current time :( // Pop used encounter from queue ConfigManager.PopEncounter(getApplicationContext()); // Server & weather connectSocket(); weatherManager.execute(longitude, latitude); while (!socket.isConnected()) ; // Send query to server sendLocation(longitude, latitude); } }); // Change the text value of the loadEncounterButton to the number of encounters available timer = new Timer(); timer.scheduleAtFixedRate(new TimerTask() { @Override public void run() { runOnUiThread(new Runnable() { public void run() { loadEncounterButton.setText("" + ConfigManager.EncounterCount(getApplicationContext())); } }); } }, 0, UPDATE_DELAY); }
From source file:org.akvo.flow.ui.fragment.SurveyedLocaleListFragment.java
@Override public void onResume() { super.onResume(); mDatabase.open();/*from w w w.j a va 2s. c o m*/ // try to find out where we are Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); String provider = mLocationManager.getBestProvider(criteria, true); if (provider != null) { Location loc = mLocationManager.getLastKnownLocation(provider); if (loc != null) { mLatitude = loc.getLatitude(); mLongitude = loc.getLongitude(); } } mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this); // Listen for data sync updates, so we can update the UI accordingly getActivity().registerReceiver(dataSyncReceiver, new IntentFilter(getString(R.string.action_data_sync))); refresh(); }
From source file:com.jesjimher.bicipalma.MesProperesActivity.java
/** Called when the activity is first created. */ @Override//from w w w . j av a 2s .c om public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.mesproperes); this.prefs = PreferenceManager.getDefaultSharedPreferences(this); // Si s'ha d'activar el wifi en inici, fer-ho WifiManager wm = (WifiManager) this.getSystemService(Context.WIFI_SERVICE); // Guardar el estado actual para restaurarlo al salir this.estatWifi = wm.isWifiEnabled(); if (prefs.getBoolean("activarWifiPref", false)) wm.setWifiEnabled(true); // Cargamos la versin cacheada de las estaciones leerCacheEstaciones(); actualizarListado(); // Iniciamos la descarga de las estaciones y su estado desde la web (en un thread aparte) descargaEstaciones = new RecuperarEstacionesTask(this); descargaEstaciones.execute(); // Inicialmente se busca por red (ms rpido) // dBuscaUbic=ProgressDialog.show(c, "",getString(R.string.buscandoubica),true,true); // Toast.makeText(getApplicationContext(), "Activando", Toast.LENGTH_SHORT).show(); locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_COARSE); providerCoarse = locationManager.getBestProvider(criteria, true); if (providerCoarse == null) { Toast.makeText(getApplicationContext(), "No hay forma de posicionarse", Toast.LENGTH_SHORT).show(); return; } locationManager.requestLocationUpdates(providerCoarse, 10, 0, (LocationListener) this); // Usar ltima ubicacin conocida de red para empezar y recibir futuras actualizaciones lBest = locationManager.getLastKnownLocation(providerCoarse); // Guardar el inicio de bsqueda de ubicacin para no pasarse de tiempo //tIni=new Date().getTime(); tIni = System.currentTimeMillis(); // Crear listeners para mostrar estacin en mapa, o abrir men con clic largo ListView lv = (ListView) findViewById(R.id.listado); lv.setOnItemClickListener((OnItemClickListener) this); lv.setOnItemLongClickListener((OnItemLongClickListener) this); }
From source file:com.cloudbees.gasp.activity.GaspLocationsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_locations); GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext()); map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); LocationManager locationManager;// ww w. j a v a2 s . com String svcName = Context.LOCATION_SERVICE; locationManager = (LocationManager) getSystemService(svcName); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setSpeedRequired(false); criteria.setCostAllowed(true); String provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); Log.i(TAG, "CURRENT LOCATION"); Log.i(TAG, "Latitude = " + location.getLatitude()); Log.i(TAG, "Longitude = " + location.getLongitude()); if (location != null) { double latitude = location.getLatitude(); double longitude = location.getLongitude(); Geocoder gc = new Geocoder(this, Locale.getDefault()); if (!Geocoder.isPresent()) Log.i(TAG, "No geocoder available"); else { try { List<Address> addresses = gc.getFromLocation(latitude, longitude, 1); StringBuilder sb = new StringBuilder(); if (addresses.size() > 0) { Address address = addresses.get(0); for (int i = 0; i < address.getMaxAddressLineIndex(); i++) sb.append(address.getAddressLine(i)).append(" "); sb.append(address.getLocality()).append(""); sb.append(address.getPostalCode()).append(" "); sb.append(address.getCountryName()); } Log.i(TAG, "Address: " + sb.toString()); } catch (IOException e) { Log.d(TAG, "IOException getting address from geocoder", e); } } } map.setMyLocationEnabled(true); LatLng myLocation = new LatLng(location.getLatitude(), location.getLongitude()); CameraPosition cameraPosition = new CameraPosition.Builder().target(myLocation).zoom(16).bearing(0).tilt(0) .build(); map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); new LocationMapper().execute(); }
From source file:com.projectattitude.projectattitude.Activities.MapActivity.java
/** * Handles everything//from w w w . j a va2s . com * @param map */ @Override public void onMapReady(GoogleMap map) { mMap = map; LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); if (ContextCompat.checkSelfPermission(MapActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(MapActivity.this, new String[] { android.Manifest.permission.ACCESS_FINE_LOCATION }, MY_PERMISSION_ACCESS_COARSE_LOCATION); } /** * http://stackoverflow.com/questions/18425141/android-google-maps-api-v2-zoom-to-current-location 4/1/2017 4:20pm */ Location location = locationManager.getLastKnownLocation(locationManager.getBestProvider(criteria, false)); if (location != null) { map.animateCamera(CameraUpdateFactory .newLatLngZoom(new LatLng(location.getLatitude(), location.getLongitude()), 13)); CameraPosition cameraPosition = new CameraPosition.Builder() .target(new LatLng(location.getLatitude(), location.getLongitude())) // Sets the center of the map to location user .zoom(15) // Sets the zoom .bearing(0) // Sets the orientation of the camera to east .tilt(40) // Sets the tilt of the camera to 30 degrees .build(); // Creates a CameraPosition from the builder map.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition)); } enableMyLocation(); //couldn't get ColorMap to work, so made one for the meantime HashMap<String, BitmapDescriptor> hm = new HashMap<String, BitmapDescriptor>(); hm.put("Anger", BitmapDescriptorFactory.fromResource(R.drawable.ic_anger_colour_36px));//defaultMarker(356)); hm.put("Confusion", BitmapDescriptorFactory.fromResource(R.drawable.ic_confusion_colour_36px));//defaultMarker(19)); hm.put("Disgust", BitmapDescriptorFactory.fromResource(R.drawable.ic_disgust_colour_36px));//defaultMarker(65)); hm.put("Fear", BitmapDescriptorFactory.fromResource(R.drawable.ic_fear_colour_36px));//defaultMarker(42)); hm.put("Happiness", BitmapDescriptorFactory.fromResource(R.drawable.ic_happiness_colour_36px));//defaultMarker(160)); hm.put("Sadness", BitmapDescriptorFactory.fromResource(R.drawable.ic_sadness_colour_36px));//defaultMarker(60)); hm.put("Shame", BitmapDescriptorFactory.fromResource(R.drawable.ic_shame_colour_36px));//defaultMarker(200)); hm.put("Surprise", BitmapDescriptorFactory.fromResource(R.drawable.ic_surprise_colour_36px));//defaultMarker(22)); //Taken from https://developers.google.com/maps/documentation/android-api/marker //On March 21st at 17:53 map.setOnInfoWindowClickListener(this); if (getIntent().hasExtra("users")) { ArrayList<User> users = (ArrayList<User>) getIntent().getSerializableExtra("users"); GPSTracker gps = new GPSTracker(MapActivity.this); //LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); //LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE); if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { latitude = Math.round(gps.getLatitude() * 10000d) / 10000d; longitude = Math.round(gps.getLongitude() * 10000d) / 10000d; if (latitude != 0 & longitude != 0) { Toast.makeText(MapActivity.this, "Found your location", Toast.LENGTH_LONG).show(); Log.d("Distance", "Current Location: " + latitude + " " + longitude); for (int i = 0; i < users.size(); i++) { Mood mood = users.get(i).getFirstMood(); // if(mood.getLatitude()!= null && mood.getLongitude() != null) { if (mood != null) { Double returned = calculateDistance(latitude, longitude, mood.getLatitude(), mood.getLongitude()); returned = returned / 1000; Log.d("Distance", "Current Distance: " + returned); Log.d("Distance", "Current comparison to: " + users.get(i).getUserName() + " " + mood.getEmotionState()); if (returned < 5) { map.addMarker(new MarkerOptions() .position(new LatLng(mood.getLatitude(), mood.getLongitude())) .title(mood.getMaker()).snippet(mood.getEmotionState()) .icon(hm.get(mood.getEmotionState()))).setTag(mood); } } } } else { Toast.makeText(MapActivity.this, "Could not find your location, please try again!", Toast.LENGTH_LONG).show(); } } else { Toast.makeText(MapActivity.this, "Please turn on GPS for locations!", Toast.LENGTH_LONG).show(); } } else if (getIntent().hasExtra("user")) { ArrayList<Mood> userMoodList = (ArrayList<Mood>) getIntent().getSerializableExtra("user"); for (int i = 0; i < userMoodList.size(); i++) { //TODO this will get EVERY mood from the user, which could be too many Mood mood = userMoodList.get(i); if (mood.getLongitude() == 0 && mood.getLatitude() == 0) { Log.d("MapMoods", "Mood: " + mood.getEmotionState() + "not mapped"); } else { map.addMarker(new MarkerOptions().position(new LatLng(mood.getLatitude(), mood.getLongitude())) .title(mood.getMaker()).snippet(mood.getEmotionState()) .icon(hm.get(mood.getEmotionState()))).setTag(mood); } } } else { Toast.makeText(MapActivity.this, "MIts Fucked, nothing go passed", Toast.LENGTH_LONG).show(); } }
From source file:uk.ac.horizon.artcodes.fragment.ExperienceRecommendFragment.java
@Nullable private Location getLocation() { if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) { final LocationManager locationManager = (LocationManager) getContext().getApplicationContext() .getSystemService(Context.LOCATION_SERVICE); float accuracy = Float.MAX_VALUE; Location location = null; for (String provider : locationManager.getProviders(new Criteria(), true)) { Location newLocation = locationManager.getLastKnownLocation(provider); if (newLocation != null) { if (newLocation.getAccuracy() < accuracy) { accuracy = newLocation.getAccuracy(); location = newLocation; }//from w w w . j a va2 s.co m } } return location; } else { Log.i("location", "No location permission"); } return null; }
From source file:dtu.ds.warnme.app.location.FollowMeLocationSource.java
private void init() { locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.POWER_MEDIUM); criteria.setAltitudeRequired(true);//from w w w . j a va2s . co m criteria.setBearingRequired(true); criteria.setSpeedRequired(true); criteria.setCostAllowed(true); }