Which LocationProvider in Android costs money to use?
The LocationManager in Android can choose LocationProviders on a specific Criteria. The Criteria class has a method isCostAllowed and setCostAllowed. Which of the LocationProvider costs the user money? Is it only the network location provider because it creates network traffic or is this just implemented because of some future possibi开发者_如何转开发lities?
One example that can cost money is a location provider that accesses a remote database of cell tower positions, or wifi access point positions. These providers will use some of your data allowance.
I don't believe there are any location providers that intrinsically cost money - the cost is in the use of your data allowance.
GPS per se do not cost any money as there is an in-built receiver in your smartphone. Network location will cost you money as there is a round-trip of lookup involved from remote database. Essentially it is the data cost that is associated with getting the fix using network location.
I just run a simple test to confirm if the NetworkProvider is considered as a provider that costs money:
LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE);
criteria.setCostAllowed(false);
String provider = manager.getBestProvider(criteria, false);
Log.d(getClass().getSimpleName(), "Best Provider is: " + provider);
There is no difference in the outcome if I set cost allowed to false or true:
08-06 14:52:25.375: DEBUG/LocationPlaygroundActivity(30782): Best Provider is: network
08-06 14:52:39.860: DEBUG/LocationPlaygroundActivity(30848): Best Provider is: network
The best provider is always network. At the moment it seems as if there is no provider that would cost the user money. Maybe this is just built in for future location provider possibilities.
精彩评论