上一篇文章 【Android笔记 二】Location获取地理位置信息(上)介绍了简单的地理位置服务的使用,今天这篇文章给大家分享以下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).//设置垂直距离的海拔高度
这里是我写的一段演示代码
单击链接打开文章
分享到:
相关推荐
主要介绍了Android使用criteria选择合适的地理位置服务实现方法,实例分析了Criteria的具体使用技巧,需要的朋友可以参考下
Android 获取经度 纬度 位置信息,在Android系统的手机上运行后,会显示出纬度和经度信息,具体的方法请参见以下代码: //方法:返回查询条件 public Criteria getCriteria(){ Criteria c = new Criteria(); ...
Hibernate中Criteria的使用,对于研究hibrnate源码有一些作用
自己写的一个获取当前手机位置的Demo,网上的资源比较多,但是难看懂。我参考了两篇博客,写的比较好。 https://www.cnblogs.com/kdkler/p/6196751.html https://www.cnblogs.com/xinaixia/p/8057785.html
criteria的相关知识及其介绍,便于java编程中使用criteria进行相关操作。
介绍了hibernate中 Criteria接口在实际开发过程中的常见使用方法及技巧
hibernate模糊查询类Criteria的使用
Hibernate中Criteria的用法
最近在做一个 Android 项目,需要用到GPS获取位置信息,从 API 查了一下,发现获取位置信息仅需极其简单的一句即可: 代码如下:getLastKnownLocation(LocationManager.GPS_PROVIDER),于是高兴地不得了。可是一写进...
Hibernate中Criteria的完整用法
初学者Android源码,获取Gps定位信息的Android源码实例,通过这个JAVA小项目,你可能学会GPS在Android手机中如何工作,定位和获取GPS等操作,代码中有注释,方便理解学习,部分代码注解: public int InfoType;//...
现在有这么一个需求:开启一个Service服务,获取当前...Android手机获取当前位置的方式:GPS定位,WIFI定位,基站定位,当前Demo使用GPS卫星定位,在LocationTool中返回Location、LocationManager两者对象,通过Loca
DetachedCriteria Criteria 使用方法 非常详细外加练习
hibernate criteria的使用方法
2种方式获取android设置可以使用的定位
Hibernate中Criteria的完整用法