上一篇文章http://www.cnblogs.com/octobershiner/archive/2011/10/24/2222401.html
介绍了简单的地理位置服务的使用,今天这篇文章给大家分享以下Criteria类的使用
在使用android lcoation的时候,可能不希望自己去硬性的选择是GPS服务还是NETWORK服务,可能是我们考虑的因素有很多,自己很难决定,Android SDK提供了一个类Criteria,直译为标准。
注意在locationManager中还有一个重要的方法就是getBestProvider()
------------------------------------------------------------------------------------------------------------------------------------------------
public String getBestProvider (Criteria criteria, boolean enabledOnly)
Since: API Level 1
Returns the name of the provider that best meets the given criteria. Only providers that are permitted to be accessed by the calling activity will be returned. If several providers meet the criteria, the one with the best accuracy is returned. If no provider meets the criteria, the criteria are loosened in the following sequence:
//翻译:返回满足给定的criteria(标准)的最佳provider,(前面一篇文章提到过两种重要provider的区别)。只有当provider权限允许的时候才会返回,如果几个provider均满足criteria设定的标准,最贴近标准的provider将会被返回。如果没有provider满足,标准将按照下面的序列放宽松。
power requirement
accuracy
bearing
speed
altitude
Note that the requirement on monetary cost is not removed in this process.
//在放宽标准的过程中,对于资费的要求不会被移除,我感觉也就是是否允许产生资费的标准不会改变
Parameters
criteria the criteria that need to be matched
enabledOnly if true then only a provider that is currently enabled is returned//这个参数为true的时候,只会返回当前可用的provider,例如GPS处于关闭状态时,就不会获得了
Returns
name of the provider that best matches the requirements
------------------------------------------------------------------------------------------------------------------------------------------------
下面详细的看一下Criteria类的解释
A class indicating the application criteria for selecting a location provider. Providers maybe ordered according to accuracy, power usage, ability to report altitude, speed, and bearing, and monetary cost.
翻译:“这个类表示了应用程序选择位置服务provider的一个标准,provider可能是根据精准度,电量使用,能否获得海拔,速度、方向和产生资费来选择的”也就是说,criteria给用户提供了多种因素的标准设置,locationManager可以根据这个设定好的标准,自动选择最慢组需求的provider。
------------------------------------------------------------------------------------------------------------------------------------------------
void setAccuracy(int accuracy)
Indicates the desired accuracy for latitude and longitude. //设置经纬度的精准度 可选参数有ACCURACY_FINE 准确 ACCURACY_COARSE 粗略
void setAltitudeRequired(boolean altitudeRequired)
Indicates whether the provider must provide altitude information.//设置是否需要获取海拔数据
void setBearingAccuracy(int accuracy)
Indicates the desired bearing accuracy. //设置方向的精确 可选参数有ACCURACY_LOW,低 ACCURACY_HIGH 高 NO_REQUIREMENT.没有要求
void setBearingRequired(boolean bearingRequired)
Indicates whether the provider must provide bearing information.//设置是否需要获得方向信息
void setCostAllowed(boolean costAllowed)
Indicates whether the provider is allowed to incur monetary cost. //设置是否允许定位过程中产生资费,比如流量等
void setHorizontalAccuracy(int accuracy)
Indicates the desired horizontal accuracy (latitude and longitude).//获取水平方向经纬度的精准度 可选参数ACCURACY_LOW, 低 ACCURACY_MEDIUM 中 ACCURACY_HIGH 高 NO_REQUIREMENT. 无要求
void setPowerRequirement(int level)
Indicates the desired maximum power level. //设置耗电量的级别
void setSpeedAccuracy(int accuracy)
Indicates the desired speed accuracy. //设置速度的精确度
void setSpeedRequired(boolean speedRequired)
Indicates whether the provider must provide speed information. //设置是否提供速度的要求
void setVerticalAccuracy(int accuracy)
Indicates the desired vertical accuracy (altitude).//设置垂直距离的海拔高度
这里是我写的一段演示代码
http://www.cnblogs.com/octobershiner/archive/2011/10/24/2223073.html