get two location provider code example

Example: get two location provider

LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(false);
criteria.setPowerRequirement(Criteria.POWER_LOW);       
 
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String providerFine = manager.getBestProvider(criteria, true);
 
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
String providerCoarse = manager.getBestProvider(criteria, true);
 
if (providerCoarse != null) {
    manager.requestLocationUpdates(providerCoarse, 5*60000, 100, this);
}
if (providerFine != null) {
    manager.requestLocationUpdates(providerFine, 5*60000, 100, this);
}

Tags:

Misc Example