List of usage examples for android.location Criteria setBearingRequired
public void setBearingRequired(boolean bearingRequired)
From source file:Main.java
/** * this criteria will settle for less accuracy, high power, and cost *///www . ja v a 2s . c o m public static Criteria createCoarseCriteria() { Criteria c = new Criteria(); c.setAccuracy(Criteria.ACCURACY_COARSE); c.setAltitudeRequired(false); c.setBearingRequired(false); c.setSpeedRequired(false); c.setCostAllowed(true); c.setPowerRequirement(Criteria.POWER_HIGH); return c; }
From source file:Main.java
public static String getBestProvider(LocationManager locationmanager) { String s = null;//from www . j a v a 2 s. c o m if (locationmanager != null) { Criteria criteria = new Criteria(); criteria.setAccuracy(2); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); criteria.setPowerRequirement(0); s = locationmanager.getBestProvider(criteria, true); if (s == null) s = "network"; } return s; }
From source file:Main.java
public static String getGpsString(Context context) { if (context == null) { return null; }/*from w w w .j av a2s .c om*/ String gps = null; Location location = null; Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingRequired(false); criteria.setCostAllowed(true); LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); String provider = locationManager.getBestProvider(criteria, true); if (provider != null) { location = locationManager.getLastKnownLocation(provider); } if (location != null) { double longtitude = location.getLongitude(); double latitude = location.getLatitude(); gps = "Lon:" + longtitude + "; Lat:" + latitude; } if (gps == null) { gps = "Lon:0; Lat:0"; } return gps; }
From source file:com.appdynamics.demo.gasp.utils.LocationServices.java
/** * Set Location Services and get current location *//*from w ww .j a v a 2 s .c o m*/ public static Location getLocation(Context context) { Location location = null; try { String svcName = Context.LOCATION_SERVICE; LocationManager locationManager = (LocationManager) context.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 = locationManager.getLastKnownLocation(provider); Log.i(TAG, "Current Latitude = " + location.getLatitude()); Log.i(TAG, "Current Longitude = " + location.getLongitude()); } catch (Exception e) { e.printStackTrace(); } return location; }
From source file:com.ushahidi.android.app.util.Util.java
/** this criteria needs high accuracy, high power, and cost */ public static Criteria createFineCriteria() { Criteria c = new Criteria(); c.setAccuracy(Criteria.ACCURACY_FINE); c.setAltitudeRequired(false);// ww w . j a v a2s . c om c.setBearingRequired(false); c.setSpeedRequired(false); c.setCostAllowed(true); c.setPowerRequirement(Criteria.POWER_HIGH); return c; }
From source file:com.airbop.library.simple.CommonUtilities.java
/** * Simple helper that gets the location criteria that we want. * @return// w w w . j av a 2s .c o 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:net.quranquiz.ui.QQMap.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.map);//from w ww. j a va 2s.c o 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.example.mohamed.a3qaqer.RegisterActvity.java
private void getloc() { if (!locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { loc_string = "none";// indicate that no gps data return;//from w w w .j av a2s. co m } 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.findcab.driver.activity.Signup.java
/** * ?GPS?/* w ww . ja va 2 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(); } }
From source file:org.navitproject.navit.NavitVehicle.java
/** * @brief Creates a new {@code NavitVehicle} * * @param context/*from ww w. j a va 2s .c om*/ * @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); } }