目录

CLASS info
public class LocationRequest implements IMessageEntity
Location request information class.

Field Summary

Return typeMethod nameDescription
Creator<LocationRequest>CREATORLocationRequest builder.

Constant Summary

TypeNameDesc
intPRIORITY_HIGH_ACCURACYUsed to request the most accurate location.
intPRIORITY_BALANCED_POWER_ACCURACYUsed to request the block-level location.
intPRIORITY_LOW_POWERUsed to request the city-level location.
intPRIORITY_NO_POWERUsed to request the location with the optimal accuracy without additional power consumption.
intPRIORITY_HD_ACCURACYUsed to request the high-precision location information. Currently, this parameter is available only for the requestLocationUpdatesEx API.

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
Used to request the most accurate location.
Constant value: 100
Constant
public static final int PRIORITY_BALANCED_POWER_ACCURACY
Used to request the block-level location.
Constant value: 102
Constant
public static final int PRIORITY_LOW_POWER
Used to request the city-level location.
Constant value: 104
Constant
public static final int PRIORITY_NO_POWER
Used to request the location with the optimal accuracy without additional power consumption.
Constant value: 105
Constant
public static final int PRIORITY_HD_ACCURACY
Used to request the high-precision location information. Currently, this parameter is available only for the requestLocationUpdatesEx API.

Constant value: 200

Public Methods

Method
public LocationRequest create()
This API is used to build a location request.
Method
public LocationRequest setPriority(int priority)
This API is used to set the request priority. If the GPS location is requested, set the priority to 100. If the network location is requested, set the priority to 102 or 104. If the location only needs to be passively received instead of being proactively requested, set the priority to 105. If high-precision location is requested, set the priority to 200.

Parameters

Parameter nameParameter desc
priorityRequest priority. The default value is 100.
Method
public LocationRequest setInterval(long millis)
This API is used to set the interval for receiving location updates, in milliseconds. If the value is 50000, a location update is received every 50 seconds.

Parameters

Parameter nameParameter desc
millisCallback interval, in milliseconds. The default value is 3600000.
Method
public LocationRequest setNumUpdates(int numUpdates)
This API is used to set the number of location updates. If the value is 3, three location updates are sent to the client.

Parameters

Parameter nameParameter desc
numUpdatesNumber of requested location updates. The default value is Integer.MAX_VALUE.
Method
public LocationRequest setFastestInterval(long millis)
This API is used to specify the shortest interval for requesting location callback. The values of Interval and FastestInterval, whichever is smaller, will be used for requesting location callback.

Parameters

Parameter nameParameter desc
millisShortest request interval, in milliseconds. The default value is 600000. If another app initiates a location request, the location is also reported to the app at the interval specified in fastestInterval.
Method
public boolean isFastestIntervalExplicitlySet()
This API is used to specify whether to use the shortest interval.

Return

Parameter nameParameter desc
booleanIndicates whether to use the shortest interval. If yes, the value true is returned. Otherwise, the value false is returned.
Method
public LocationRequest setExpirationTime(long millis)
This API is used to set the request expiration time, in milliseconds since boot. You can use the SystemClock.elapsedRealtime() method to obtain the number of milliseconds elapsed from the boot time to the current time. If the location update needs to be stopped 200 seconds later, the request expiration time should equal to the return result of SystemClock.elapsedRealtime() plus 200000.

Parameters

Parameter nameParameter desc
millisRequest expiration time, in milliseconds. The default value is Long.MAX_VALUE.
Method
public LocationRequest setExpirationDuration(long millis)
This API is used to set the request expiration duration. Different from expirationTime, the ExpirationDuration parameter does not consider the boot time. If the location update needs to be stopped 200 seconds later, the request expiration duration should be 200000.

Parameters

Parameter nameParameter desc
millisRequest expiration duration, in milliseconds. The default value is Long.MAX_VALUE.
Method
public LocationRequest setSmallestDisplacement(float smallestDisplacement)
This API is used to set the minimum displacement between location updates, in meters. If the displacement between location updates meets the specified parameter value, the location updates are sent to the client.

Parameters

Parameter nameParameter desc
smallestDisplacementMinimum displacement between location updates, in meters. The default value is 0.
Method
public LocationRequest setMaxWaitTime(long millis)
This API is used to set the maximum waiting time.

Parameters

Parameter nameParameter desc
millisMaximum waiting time.
Method
public LocationRequest setNeedAddress(boolean needAddress)

This API is used to specify whether to return the address information

Parameters

Parameter nameParameter desc
needAddress

Indicates whether to return the address information. The default value is false.

Method
public LocationRequest setLanguage(String language)
This API is used to set the language.

Parameters

Parameter nameParameter desc
languageLanguage. The value consists of two letters and complies with the ISO 639-1 international standard. By default, the value is empty.
Method
public LocationRequest setCountryCode(String countryCode)
This API is used to set the country code.

Parameters

Parameter nameParameter desc
countryCodeCountry code. The value consists of two letters and complies with the ISO 3166-1 international standard. By default, the value is empty.