List of usage examples for android.location Criteria setAccuracy
public void setAccuracy(int accuracy)
From source file:com.dwdesign.tweetings.activity.NearbyMapViewerActivity.java
protected void getLocationAndCenterMap() { LocationManager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); final String provider = mLocationManager.getBestProvider(criteria, true); Location mRecentLocation = null; if (provider != null) { mRecentLocation = mLocationManager.getLastKnownLocation(provider); } else {/*from w ww . j a v a2 s.c o m*/ Toast.makeText(this, R.string.cannot_get_location, Toast.LENGTH_SHORT).show(); } if (mRecentLocation != null && isNativeMapSupported()) { NativeNearbyMapFragment aFragment = (NativeNearbyMapFragment) mFragment; aFragment.setCenter(mRecentLocation); } }
From source file:com.dwdesign.tweetings.activity.MapViewerActivity.java
protected void getLocationAndCenterMap() { LocationManager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); final String provider = mLocationManager.getBestProvider(criteria, true); Location mRecentLocation = null; if (provider != null) { mRecentLocation = mLocationManager.getLastKnownLocation(provider); } else {/* www . j av a2 s. c om*/ Toast.makeText(this, R.string.cannot_get_location, Toast.LENGTH_SHORT).show(); } if (mRecentLocation != null && isNativeMapSupported()) { NativeMapFragment aFragment = (NativeMapFragment) mFragment; aFragment.setCenter(mRecentLocation); } }
From source file:net.quranquiz.ui.QQMap.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map);//from w w w .j a v a 2 s . co m map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); map.setOnMarkerClickListener((OnMarkerClickListener) this); cairo = new LatLng(30.1, 31.45); LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE); boolean enabledGPS = service.isProviderEnabled(LocationManager.GPS_PROVIDER); // Check if enabled and if not send user to the GSP settings // Better solution would be to display a dialog and suggesting to // go to the settings if (!enabledGPS) { Toast.makeText(this, "GPS signal not found", Toast.LENGTH_LONG).show(); startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); // Initialize the location fields if (location != null) { Toast.makeText(this, "Selected Provider " + provider, Toast.LENGTH_SHORT).show(); meMarker = map.addMarker( new MarkerOptions().position(cairo).title("That's Me").snippet("a normal QuranQuiz Node!") .icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_launcher))); map.moveCamera(CameraUpdateFactory.newLatLngZoom(cairo, 12.0f)); onLocationChanged(location); } else { //do something } }
From source file:com.jeremy.tripcord.main.TripcordFragment.java
private CameraUpdate getLastKnownLocation() { LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_LOW); String provider = lm.getBestProvider(criteria, true); if (provider == null) { return null; }/*from w w w. java 2s.c o m*/ Location loc = lm.getLastKnownLocation(provider); if (loc != null) { return CameraUpdateFactory.newCameraPosition( CameraPosition.fromLatLngZoom(new LatLng(loc.getLatitude(), loc.getLongitude()), 14.0f)); } return 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:it.ms.theing.loquitur.functions.LocationInterface.java
private Location getLocation() { done = true;//from w w w .j a va 2 s . com long timeInMillis = Calendar.getInstance().getTimeInMillis(); Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); String fine = locationManager.getBestProvider(criteria, true); if (fine == null) return null; Location location = locationManager.getLastKnownLocation(fine); if (location != null) { if (timeInMillis - location.getTime() < TIMEVAL) { return location; } } criteria.setAccuracy(Criteria.ACCURACY_COARSE); String coarse = locationManager.getBestProvider(criteria, true); if (!(fine.equals(coarse))) { location = locationManager.getLastKnownLocation(fine); if (location != null) { if (timeInMillis - location.getTime() < TIMEVAL) { return location; } } } timeout.postDelayed(tout, TIMEOUT); // At most 1 minute //locationManager.requestSingleUpdate(fine, ll, Looper.myLooper()); locationManager.requestSingleUpdate(fine, ll, null); done = false; return null; }
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;//from w ww.jav a 2 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.example.mohamed.a3qaqer.RegisterActvity.java
private void getloc() { if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { loc_string = "none";// indicate that no gps data return;/*ww w .ja va 2 s .com*/ } Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setBearingRequired(true); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); criteria.setAltitudeRequired(false); String bestProvider = locationManager.getBestProvider(criteria, true); if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } locationManager.requestLocationUpdates(bestProvider, 2000, 10, new LocationListener() { @Override public void onStatusChanged(String s, int i, Bundle bundle) { } @Override public void onProviderEnabled(String s) { } @Override public void onProviderDisabled(String s) { } @Override public void onLocationChanged(final Location location) { } }); Location myLocation = locationManager.getLastKnownLocation(LocationManager.PASSIVE_PROVIDER); double longitude = myLocation.getLongitude(); double latitude = myLocation.getLatitude(); loc_string = latitude + "-" + longitude; }
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);/* w ww .j av a 2 s . co 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.findcab.driver.activity.Signup.java
/** * ?GPS?// w w w . jav a2 s. co m */ private void initLocation() { LocationManager locationManager; String serviceName = Context.LOCATION_SERVICE; locationManager = (LocationManager) this.getSystemService(serviceName); // ? Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(Criteria.POWER_LOW); String provider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(provider); if (location != null) { lat = location.getLatitude(); lng = location.getLongitude(); } }