Reputation: 2079
I search for the best Provider using this code:
Criteria criteria = new Criteria();
criteria.setPowerRequirement(Criteria.POWER_MEDIUM);
criteria.setAccuracy(Criteria.ACCURACY_HIGH);
criteria.setSpeedRequired(false);
criteria.setAltitudeRequired(false);
criteria.setBearingRequired(false);
criteria.setCostAllowed(false);
return locationManager.getBestProvider(criteria, true);
Obviously, I have necessary permissions:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
However, it gives me an error
network provider does not exist, accuracy=3
The strange thing is that if I use
criteria.setAccuracy(Criteria.ACCURACY_FINE);//FINE, not HIGH
it works just ok. What could be the reason? How can I use the HIGH value?
Upvotes: 0
Views: 149
Reputation: 186
See Criteria.setAccuracy:
/**
* Indicates the desired accuracy for latitude and longitude. Accuracy
* may be {@link #ACCURACY_FINE} if desired location
* is fine, else it can be {@link #ACCURACY_COARSE}.
* More accurate location may consume more power and may take longer.
*
* @throws IllegalArgumentException if accuracy is not one of the supported constants
*/
public void setAccuracy(int accuracy) {
if (accuracy < NO_REQUIREMENT || accuracy > ACCURACY_COARSE) {
throw new IllegalArgumentException("accuracy=" + accuracy);
}
if (accuracy == ACCURACY_FINE) {
mHorizontalAccuracy = ACCURACY_HIGH;
} else {
mHorizontalAccuracy = ACCURACY_LOW;
}
}
setAccuracy(ACCURACY_FINE) will assign the mHorizontalAccuracy to ACCURACY_HIGH
Upvotes: 1