List of usage examples for android.location Criteria Criteria
public Criteria()
From source file:Main.java
/** * this criteria will settle for less accuracy, high power, and cost *//* w ww .j av a2 s . co 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) throws IllegalArgumentException { Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setPowerRequirement(Criteria.NO_REQUIREMENT); return locationManager.getBestProvider(criteria, true); }
From source file:Main.java
public static Criteria getGeoCriteria() { if (criteria == null) criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_MEDIUM); criteria.setPowerRequirement(Criteria.POWER_LOW); return criteria; }
From source file:Main.java
public static String getBestProvider(LocationManager locationmanager) { String s = null;/* w w w. j av 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 double[] getLastKnownLocation(Activity a) { LocationManager locationManager = (LocationManager) a.getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); String provider = locationManager.getBestProvider(criteria, true); System.out.println("provider: " + provider); Location location = locationManager.getLastKnownLocation(provider); return new double[] { location.getLatitude(), location.getLongitude() }; }
From source file:Main.java
public static String getGpsString(Context context) { if (context == null) { return null; }//from w w w .j a va 2s . com 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:Main.java
public static Location getLocation(Context context) { LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // Gets the last known location from the best service. String bestLocationProvider = locationManager.getBestProvider(new Criteria(), true /*enabled only*/); return locationManager.getLastKnownLocation(bestLocationProvider); }
From source file:com.appdynamics.demo.gasp.utils.LocationServices.java
/** * Set Location Services and get current location *///from w w w.j a va2 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.ddpclient.spiovesan.ddpclient.LogService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); // Get the location manager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); // Define the criteria how to select the locatioin provider -> use // default//from ww w . ja v a 2s .c o m Criteria criteria = new Criteria(); provider = locationManager.getBestProvider(criteria, false); location = locationManager.getLastKnownLocation(provider); locationManager.requestLocationUpdates(provider, 400, 1, this); //Announcement about starting Toast.makeText(this, "Starting the Log Service: " + provider, Toast.LENGTH_SHORT).show(); //Start a Background thread isRunning = true; Thread backgroundThread = new Thread(new BackgroundThread()); backgroundThread.start(); // We want this service to continue running until it is explicitly // stopped, so return sticky. return START_STICKY; }
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 {// w ww . ja va2 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); } }