| Class Info |
|---|
| public class LocationRequest implements Parcelable, IMessageEntity Location request information class. An instance of this class will be returned when the create() method in this class is called. |
Java
LocationRequest mLocationRequest;
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(5000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); Kotlin
val mLocationRequest: LocationRequest
mLocationRequest = LocationRequest()
mLocationRequest.interval = 5000
mLocationRequest.priority = LocationRequest.PRIORITY_HIGH_ACCURACY | Qualifier and Type | Field and Description |
|---|---|
| static final Creator<LocationRequest> | Builder of LocationRequest. |
| static final int | PRIORITY_BALANCED_POWER_ACCURACY Used to request the block-level location. |
| static final int | Used to request the high-precision location. Currently, this parameter is available only for the requestLocationUpdatesEx method. CAUTION:
|
| static final int | Used to request the most accurate location. |
| static final int | Used to request the city-level location. |
| static final int | Used to request the location with the optimal accuracy without additional power consumption. |
| static final int | Used to request the indoor location. Currently, this field can only be used by the requestLocationUpdatesEx method. |
| static final int | PRIORITY_HIGH_ACCURACY_AND_INDOOR Used to request the indoor location and fused location. Currently, this field can only be used by the requestLocationUpdatesEx method. |
| Qualifier and Type | Method Name and Description |
|---|---|
| LocationRequest | create() Creates a LocationRequest object. |
| boolean | isFastestIntervalExplicitlySet() Checks whether the fastest request interval is used. |
| LocationRequest | setCountryCode(String countryCode) Sets the country code. |
| LocationRequest | setExpirationDuration(long millis) Sets the request expiration duration, in milliseconds. |
| LocationRequest | setExpirationTime(long millis) Sets the request expiration time, in milliseconds. |
| LocationRequest | setFastestInterval(long millis) Sets the fastest interval for requesting location updates, in milliseconds. The values of Interval and FastestInterval, whichever is smaller, will be used for requesting location updates. If fastestInterval needs to be set, you are advised to set it to a value far less than that of Interval. |
| LocationRequest | setInterval(long millis) Sets the interval for requesting location updates, in milliseconds. |
| LocationRequest | setLanguage(String language) Sets the language. |
| LocationRequest | setMaxWaitTime(long millis) Sets the maximum waiting time for location updates, in milliseconds. |
| LocationRequest | setNeedAddress(boolean needAddress) Sets whether to return the address information. |
| LocationRequest | setNumUpdates(int numUpdates) Sets the number of location updates. If the value is 3, the app will receive three location updates. |
| LocationRequest | setPriority(int priority) Sets the location type. CAUTION:
|
| LocationRequest | setSmallestDisplacement(float smallestDisplacement) Sets the smallest displacement between two locations, in meters. |
| Fields |
|---|
| public static final Creator<LocationRequest> CREATOR Builder of LocationRequest, which is used to deserialize location request information. |
| Fields |
|---|
| public static final int PRIORITY_BALANCED_POWER_ACCURACY Used to request the block-level location. PRIORITY_BALANCED_POWER_ACCURACY: 102 For details about other constant values, please refer to Constant Values. |
| Fields |
|---|
| public static final int PRIORITY_HD_ACCURACY Used to request the high-precision location. Currently, this parameter is available only for the requestLocationUpdatesEx method. PRIORITY_HD_ACCURACY: 200 For details about other constant values, please refer to Constant Values. |
| Fields |
|---|
| public static final int PRIORITY_HIGH_ACCURACY Used to request the most accurate location. PRIORITY_HIGH_ACCURACY: 100 For details about other constant values, please refer to Constant Values. |
| Fields |
|---|
| public static final int PRIORITY_LOW_POWER Used to request the city-level location. PRIORITY_LOW_POWER: 104 For details about other constant values, please refer to Constant Values. |
| Fields |
|---|
| public static final int PRIORITY_NO_POWER Used to request the location with the optimal accuracy without additional power consumption. PRIORITY_NO_POWER: 105 For details about other constant values, please refer to Constant Values. |
| Fields |
|---|
| public static final int PRIORITY_INDOOR Used to request indoor location. PRIORITY_INDOOR: 300 For details about other constant values, please refer to Constant Values. |
| Fields |
|---|
| public static final int PRIORITY_HIGH_ACCURACY_AND_INDOOR Used to request the indoor location and fused location. PRIORITY_HIGH_ACCURACY_AND_INDOOR: 400 For details about indoor location constraints, please refer to Developing the Indoor Location Service. For other constant values, please refer to Constant Values. |
| Method |
|---|
| public static LocationRequest create() Creates a LocationRequest object. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request class. |
| Method |
|---|
| public boolean isFastestIntervalExplicitlySet() Checks whether the fastest request interval is used. |
Returns
| Type | Description |
|---|---|
| boolean | true if the fastest request interval is used; false otherwise. |
| Method |
|---|
| public LocationRequest setCountryCode(String countryCode) Sets the country code. |
Parameters
| Name | Description |
|---|---|
| countryCode | Country code. The value is a two-letter code complying with the ISO 3166-1 standard. By default, this parameter is left empty. Currently, the options include only EN and CN. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request. |
| Method |
|---|
| public LocationRequest setExpirationDuration(long millis) Sets the request expiration duration. Different from expirationTime, the ExpirationDuration parameter is irrelevant to the boot time. If the location update needs to be stopped 200 seconds later, the request expiration duration should be 200000. |
Parameters
| Name | Description |
|---|---|
| millis | Request expiration duration, in milliseconds. The default value is Long.MAX_VALUE. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request. |
| Method |
|---|
| public LocationRequest setExpirationTime(long millis) Sets the request expiration time since boot, in milliseconds. 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 the return result of SystemClock.elapsedRealtime() plus 200000. |
Parameters
| Name | Description |
|---|---|
| millis | Request expiration time, in milliseconds. The default value is Long.MAX_VALUE. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request. |
| Method |
|---|
| public LocationRequest setFastestInterval(long millis) Sets the fastest interval for requesting location updates. The default value is one sixth of Interval. |
Parameters
| Name | Description |
|---|---|
| millis | Fastest request interval, in milliseconds. The default value is 600000. If another app initiates a location request, the location is also reported to that app at the interval specified in fastestInterval. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request. |
Throws
| Name | Description |
|---|---|
| IllegalArgumentException | Invalid parameter. The value of millis is less than 0. Ensure that the parameter value is correct. |
| Method |
|---|
| public LocationRequest setInterval(long millis) Sets the interval for requesting location updates. If the value is 50000, the app will receive a location update every 50 seconds. |
Parameters
| Name | Description |
|---|---|
| millis | Interval for requesting location updates, in milliseconds. The default value is 3600000. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request. |
Throws
| Name | Description |
|---|---|
| IllegalArgumentException | Invalid parameter. The value of millis is less than 0. Ensure that the parameter value is correct. |
| Method |
|---|
| public LocationRequest setLanguage(String language) Sets the language. |
Parameters
| Name | Description |
|---|---|
| language | Language, which is a two-letter code complying with the ISO 639-1 standard. For example, en indicates English. By default, this parameter is left empty. Currently, the options include only en and zh. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request. |
| Method |
|---|
| public LocationRequest setMaxWaitTime(long millis) Sets the maximum waiting time for location updates, in milliseconds. When the setting takes effect, the time specified by maxWaitTime will be used as the location update period. After the location update time is reached, locations in the period will be returned to the app at a time. NOTE:
|
Parameters
| Name | Description |
|---|---|
| millis | Maximum waiting time, in milliseconds. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request. |
| Method |
|---|
| public LocationRequest setNeedAddress(boolean needAddress) Sets whether to return the address information. |
Parameters
| Name | Description |
|---|---|
| needAddress | Indicates whether to return the address information. The default value is false. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request. |
| Method |
|---|
| public LocationRequest setNumUpdates(int numUpdates) Sets the number of location updates. If the value is 3, the app will receive three location updates. |
Parameters
| Name | Description |
|---|---|
| numUpdates | Number of requested location updates. The default value is Integer.MAX_VALUE. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request. |
Throws
| Name | Description |
|---|---|
| IllegalArgumentException | Invalid parameter. The value of numUpdates is less than or equal to 0. Ensure that the parameter value is correct. |
| Method |
|---|
| public LocationRequest setPriority(int priority) Sets the location type. If the GNSS location is requested, set priority to 100. If the network location is requested, set priority to 102 or 104. If the location only needs to be passively received instead of being proactively requested, set priority to 105. If the high-precision location is requested, set priority to 200. If the indoor location is requested, set priority to 300. |
Parameters
| Name | Description |
|---|---|
| priority | Requested location type. The default value is 102. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request. |
Throws
| Name | Description |
|---|---|
| IllegalArgumentException | Invalid parameter. Ensure that the value of priority is one of the location types defined by LocationRequest. |
| Method |
|---|
| public LocationRequest setSmallestDisplacement(float smallestDisplacement) Sets the smallest displacement for location updates. If the displacement between two locations is greater than or equal to the specified parameter value, a location update will be sent to the app. |
Parameters
| Name | Description |
|---|---|
| smallestDisplacement | Smallest displacement between two locations, in meters. The default value is 0. |
Returns
| Type | Description |
|---|---|
| LocationRequest | Location request. |
Throws
| Name | Description |
|---|---|
| IllegalArgumentException | Invalid parameter. The value of smallestDisplacement is less than 0.0. Ensure that the parameter value is correct. |