目录

CLASS info
public class LocationRequest implements IMessageEntity
定位的请求信息类。

Field Summary

Return typeMethod nameDescription
Creator<LocationRequest>CREATORLocationRequest构建器

Constant Summary

TypeNameDesc
intPRIORITY_HIGH_ACCURACY用于请求最准确的位置
intPRIORITY_BALANCED_POWER_ACCURACY用于请求“街区”级精度
intPRIORITY_LOW_POWER用于请求“城市”级别的准确性
intPRIORITY_NO_POWER用于在零额外功耗下请求最佳精度
intPRIORITY_HD_ACCURACY用于请求高精度的位置信息,当前仅限于requestLocationUpdatesEx接口使用。

Public Method Summary

Return typeMethod name
LocationRequestcreate()
LocationRequestsetPriority(int priority)
LocationRequestsetInterval(long millis)
LocationRequestsetNumUpdates(int numUpdates)
LocationRequestsetFastestInterval(long millis)
booleanisFastestIntervalExplicitlySet()
LocationRequestsetExpirationTime(long millis)
LocationRequestsetExpirationDuration(long millis)
LocationRequestsetSmallestDisplacement(float smallestDisplacement)
LocationRequestsetMaxWaitTime(long millis)
LocationRequestsetNeedAddress(boolean needAddress)
LocationRequestsetLanguage(String language)
LocationRequestsetCountryCode(String countryCode)

Constants

Constant
public static final int PRIORITY_HIGH_ACCURACY
用于请求最准确的位置。
默认值: 100
Constant
public static final int PRIORITY_BALANCED_POWER_ACCURACY
用于请求“街区”级精度。
默认值: 102
Constant
public static final int PRIORITY_LOW_POWER
用于请求“城市”级别的准确性。
默认值: 104
Constant
public static final int PRIORITY_NO_POWER
用于在零额外功耗下请求最佳精度。
默认值: 105
Constant
public static final int PRIORITY_HD_ACCURACY
用于请求高精度的位置信息,当前仅限于requestLocationUpdatesEx接口使用。
默认值: 200

Public Methods

Method
public LocationRequest create()
创建LocationRequest。
Method
public LocationRequest setPriority(int priority)
设置优先级,如果请求GPS位置,则值为100;如请求网络位置,则值为102或104;如不需要主动请求位置,仅需被动接收位置,则值为105。如果请求高精度位置信息,则值为200。

Parameters

Parameter nameParameter desc
priority请求的优先级,默认为100。
Method
public LocationRequest setInterval(long millis)
请求位置回调的时间间隔。假如值为50000,则位置请求每隔50秒回调一次结果。

Parameters

Parameter nameParameter desc
millis回调时间间隔,以毫秒为单位,默认为3600000。
Method
public LocationRequest setNumUpdates(int numUpdates)
请求位置的回调次数,假如值为3时,则只回调3次结果给客户端。

Parameters

Parameter nameParameter desc
numUpdates位置请求回调次数,默认为Integer.MAX_VALUE。
Method
public LocationRequest setFastestInterval(long millis)
请求位置回调的最快时间间隔,取Interval和FastestInterval的较小值。

Parameters

Parameter nameParameter desc
millis请求的最快时间间隔,以毫秒为单位,默认为600000。如果有其他应用发起位置请求,满足fastestInterval周期后,同样会上报位置。
Method
public boolean isFastestIntervalExplicitlySet()
是否使用最快时间间隔。

Return

Parameter nameParameter desc
boolean如果使用最快时间间隔,则返回true;否则返回false。
Method
public LocationRequest setExpirationTime(long millis)
请求到期时间,该时间自开机启动算起,开机启动到当前时间可使用SystemClock.elapsedRealtime()获取。假如200秒后位置回调需要停止,则该参数值应为SystemClock.elapsedRealtime() + 200000。

Parameters

Parameter nameParameter desc
millis请求到期时间,以毫秒为单位,默认为Long.MAX_VALUE。
Method
public LocationRequest setExpirationDuration(long millis)
请求到期时间段,该参数与expirationTime的区别为,该参数不需要考虑开机启动时间。假如200秒后位置回调需要停止,则该参数值应为200000。

Parameters

Parameter nameParameter desc
millis请求到期时间,以毫秒为单位,默认为Long.MAX_VALUE。
Method
public LocationRequest setSmallestDisplacement(float smallestDisplacement)
位置更新的最小位移。两次回调位置之间的距离满足该参数的值,则进行位置回调。

Parameters

Parameter nameParameter desc
smallestDisplacement位置更新的最小位移,以米为单位,默认为0。
Method
public LocationRequest setMaxWaitTime(long millis)
设置最长等待时间。

Parameters

Parameter nameParameter desc
millis最长等待时间。
Method
public LocationRequest setNeedAddress(boolean needAddress)
设置是否需要返回地址信息

Parameters

Parameter nameParameter desc
needAddress设置是否需要返回地址信息,默认为false
Method
public LocationRequest setLanguage(String language)
设置语言

Parameters

Parameter nameParameter desc
language设置语言,2字母代码,使用ISO 639-1国际标准,默认为空
Method
public LocationRequest setCountryCode(String countryCode)
设置国家

Parameters

Parameter nameParameter desc
countryCode设置国家,2字母代码,使用ISO 3166-1国际标准,默认为空