1e41f4b71Sopenharmony_ci# Location 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Overview 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciProvides APIs for querying the location switch status, and starting and stopping location. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ci**Since**: 13 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Summary 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ci### File 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci| Name| Description| 17e41f4b71Sopenharmony_ci| -------- | -------- | 18e41f4b71Sopenharmony_ci| [oh_location.h](oh__location_8h.md) | Defines APIs for querying the location switch status, and starting and stopping location. | 19e41f4b71Sopenharmony_ci| [oh_location_type.h](oh__location__type_8h.md) | Defines common attributes of the location service. | 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci### Structs 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci| Name| Description| 25e41f4b71Sopenharmony_ci| -------- | -------- | 26e41f4b71Sopenharmony_ci| struct [Location_BasicInfo](_location___basic_info.md) | Struct for the basic location information. | 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci### Types 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci| Name| Description| 32e41f4b71Sopenharmony_ci| -------- | -------- | 33e41f4b71Sopenharmony_ci| typedef enum [Location_ResultCode](#location_resultcode-1) [Location_ResultCode](#location_resultcode) | Enumerates error codes of the location service. | 34e41f4b71Sopenharmony_ci| typedef enum [Location_UseScene](#location_usescene-1) [Location_UseScene](#location_usescene) | Enumerates use scenes in a location request. | 35e41f4b71Sopenharmony_ci| typedef enum [Location_PowerConsumptionScene](#location_powerconsumptionscene-1) [Location_PowerConsumptionScene](#location_powerconsumptionscene) | Enumerates power consumption scenarios in a location request. | 36e41f4b71Sopenharmony_ci| typedef enum [Location_SourceType](#location_sourcetype-1) [Location_SourceType](#location_sourcetype) | Defines the source of location information. | 37e41f4b71Sopenharmony_ci| typedef struct [Location_BasicInfo](_location___basic_info.md) [Location_BasicInfo](#location_basicinfo) | Defines the struct for the basic location information. | 38e41f4b71Sopenharmony_ci| typedef struct [Location_Info](#location_info) [Location_Info](#location_info) | Defines the struct for the location information. | 39e41f4b71Sopenharmony_ci| typedef void(\* [Location_InfoCallback](#location_infocallback)) ([Location_Info](#location_info) \*location, void \*userData) | Defines the callback for receiving reported location information. | 40e41f4b71Sopenharmony_ci| typedef struct [Location_RequestConfig](#location_requestconfig) [Location_RequestConfig](#location_requestconfig) | Defines the struct for the location request configuration. | 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci### Enums 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci| Name| Description| 46e41f4b71Sopenharmony_ci| -------- | -------- | 47e41f4b71Sopenharmony_ci| [Location_ResultCode](#location_resultcode-1) {<br>LOCATION_SUCCESS = 0, LOCATION_PERMISSION_DENIED = 201, LOCATION_INVALID_PARAM = 401, LOCATION_NOT_SUPPORTED = 801,<br>LOCATION_SERVICE_UNAVAILABLE = 3301000, LOCATION_SWITCH_OFF = 3301100<br>} | Enumerates error codes of the location service. | 48e41f4b71Sopenharmony_ci| [Location_UseScene](#location_usescene-1) { LOCATION_USE_SCENE_NAVIGATION = 0x0401, LOCATION_USE_SCENE_SPORT = 0x0402, LOCATION_USE_SCENE_TRANSPORT = 0x0403, LOCATION_USE_SCENE_DAILY_LIFE_SERVICE = 0x0404 } | Enumerates use scenes in a location request. | 49e41f4b71Sopenharmony_ci| [Location_PowerConsumptionScene](#location_powerconsumptionscene-1) { LOCATION_HIGH_POWER_CONSUMPTION = 0x0601, LOCATION_LOW_POWER_CONSUMPTION = 0x0602, LOCATION_NO_POWER_CONSUMPTION = 0x0603 } | Enumerates power consumption scenarios in a location request. | 50e41f4b71Sopenharmony_ci| [Location_SourceType](#location_sourcetype-1) { LOCATION_SOURCE_TYPE_GNSS = 1, LOCATION_SOURCE_TYPE_NETWORK = 2, LOCATION_SOURCE_TYPE_INDOOR = 3, LOCATION_SOURCE_TYPE_RTK = 4 } | Defines the source of location information. | 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci### Functions 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci| Name| Description| 56e41f4b71Sopenharmony_ci| -------- | -------- | 57e41f4b71Sopenharmony_ci| [Location_ResultCode](#location_resultcode-1) [OH_Location_IsLocatingEnabled](#oh_location_islocatingenabled) (bool \*enabled) | Checks whether the location switch is enabled. | 58e41f4b71Sopenharmony_ci| [Location_ResultCode](#location_resultcode-1) [OH_Location_StartLocating](#oh_location_startlocating) (const [Location_RequestConfig](#location_requestconfig) \*requestConfig) | Starts locating and subscribes to location changes. | 59e41f4b71Sopenharmony_ci| [Location_ResultCode](#location_resultcode-1) [OH_Location_StopLocating](#oh_location_stoplocating) (const [Location_RequestConfig](#location_requestconfig) \*requestConfig) | Stops locating and unsubscribes from location changes. | 60e41f4b71Sopenharmony_ci| [Location_BasicInfo](_location___basic_info.md) [OH_LocationInfo_GetBasicInfo](#oh_locationinfo_getbasicinfo) ([Location_Info](#location_info) \*location) | Obtains basic location information. | 61e41f4b71Sopenharmony_ci| [Location_ResultCode](#location_resultcode-1) [OH_LocationInfo_GetAdditionalInfo](#oh_locationinfo_getadditionalinfo) ([Location_Info](#location_info) \*location, char \*additionalInfo, uint32_t length) | Obtains the additional information in the location information. | 62e41f4b71Sopenharmony_ci| [Location_RequestConfig](#location_requestconfig) \* [OH_Location_CreateRequestConfig](#oh_location_createrequestconfig) (void) | Creates a **Location_RequestConfig** instance. | 63e41f4b71Sopenharmony_ci| void [OH_Location_DestroyRequestConfig](#oh_location_destroyrequestconfig) ([Location_RequestConfig](#location_requestconfig) \*requestConfig) | Destroys the **Location_RequestConfig** instance and reclaims the memory. | 64e41f4b71Sopenharmony_ci| void [OH_LocationRequestConfig_SetUseScene](#oh_locationrequestconfig_setusescene) ([Location_RequestConfig](#location_requestconfig) \*requestConfig, [Location_UseScene](#location_usescene) useScene) | Sets the use scene in the location request configuration.<br>**useScene** takes precedence over **powerConsumptionScene** in [Location_RequestConfig](#location_requestconfig).<br>If **useScene** is set, **powerConsumptionScene** is invalid.<br>Otherwise, **powerConsumptionScene** takes effect.<br>If neither of the two parameters is set, **useScene** is set to **LOCATION_USE_SCENE_DAILY_LIFE_SERVICE** by default,<br>and **powerConsumptionScene** is invalid.| 65e41f4b71Sopenharmony_ci| void [OH_LocationRequestConfig_SetPowerConsumptionScene](#oh_locationrequestconfig_setpowerconsumptionscene) ([Location_RequestConfig](#location_requestconfig) \*requestConfig, [Location_PowerConsumptionScene](#location_powerconsumptionscene) powerConsumptionScene) | Sets the power consumption scene in the location request configuration. | 66e41f4b71Sopenharmony_ci| void [OH_LocationRequestConfig_SetInterval](#oh_locationrequestconfig_setinterval) ([Location_RequestConfig](#location_requestconfig) \*requestConfig, int interval) | Sets the location reporting interval in the location request configuration. | 67e41f4b71Sopenharmony_ci| void [OH_LocationRequestConfig_SetCallback](#oh_locationrequestconfig_setcallback) ([Location_RequestConfig](#location_requestconfig) \*requestConfig, [Location_InfoCallback](#location_infocallback) callback, void \*userData) | Sets the callback function. | 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci 70e41f4b71Sopenharmony_ci## Type Description 71e41f4b71Sopenharmony_ci 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci### Location_BasicInfo 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci``` 76e41f4b71Sopenharmony_citypedef struct Location_BasicInfo Location_BasicInfo 77e41f4b71Sopenharmony_ci``` 78e41f4b71Sopenharmony_ci**Description** 79e41f4b71Sopenharmony_ciDefines the struct for the basic location information. 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci**Since**: 13 82e41f4b71Sopenharmony_ci 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci### Location_Info 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci``` 87e41f4b71Sopenharmony_citypedef struct Location_Info Location_Info 88e41f4b71Sopenharmony_ci``` 89e41f4b71Sopenharmony_ci**Description** 90e41f4b71Sopenharmony_ciDefines the struct for the location information. 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci**Since**: 13 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci### Location_InfoCallback 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci``` 98e41f4b71Sopenharmony_citypedef void(* Location_InfoCallback) (Location_Info *location, void *userData) 99e41f4b71Sopenharmony_ci``` 100e41f4b71Sopenharmony_ci**Description** 101e41f4b71Sopenharmony_ciDefines the callback for receiving reported location information. 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci**Since**: 13 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci**Parameters** 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci| Name| Description| 108e41f4b71Sopenharmony_ci| -------- | -------- | 109e41f4b71Sopenharmony_ci| location | Pointer to the [Location_Info](#location_info) instance, which carries the latest location information.<br>The memory occupied by the instance will be reclaimed when [Location_InfoCallback](#location_infocallback) is complete.<br>Before calling this API, call APIs such as [OH_LocationInfo_GetBasicInfo](#oh_locationinfo_getbasicinfo) to obtain the location information.| 110e41f4b71Sopenharmony_ci| userData | Pointer to the **userData** struct or object. This parameter is passed in through [OH_LocationRequestConfig_SetCallback](#oh_locationrequestconfig_setcallback).| 111e41f4b71Sopenharmony_ci 112e41f4b71Sopenharmony_ci 113e41f4b71Sopenharmony_ci### Location_PowerConsumptionScene 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci``` 116e41f4b71Sopenharmony_citypedef enum Location_PowerConsumptionScene Location_PowerConsumptionScene 117e41f4b71Sopenharmony_ci``` 118e41f4b71Sopenharmony_ci**Description** 119e41f4b71Sopenharmony_ciEnumerates power consumption scenarios in a location request. 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ci**Since**: 13 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci 124e41f4b71Sopenharmony_ci### Location_RequestConfig 125e41f4b71Sopenharmony_ci 126e41f4b71Sopenharmony_ci``` 127e41f4b71Sopenharmony_citypedef struct Location_RequestConfig Location_RequestConfig 128e41f4b71Sopenharmony_ci``` 129e41f4b71Sopenharmony_ci**Description** 130e41f4b71Sopenharmony_ciDefines the struct for the location request configuration. 131e41f4b71Sopenharmony_ci 132e41f4b71Sopenharmony_ci**Since**: 13 133e41f4b71Sopenharmony_ci 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci### Location_ResultCode 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci``` 138e41f4b71Sopenharmony_citypedef enum Location_ResultCode Location_ResultCode 139e41f4b71Sopenharmony_ci``` 140e41f4b71Sopenharmony_ci**Description** 141e41f4b71Sopenharmony_ciEnumerates error codes of the location service. 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci**Since**: 13 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci 146e41f4b71Sopenharmony_ci### Location_SourceType 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci``` 149e41f4b71Sopenharmony_citypedef enum Location_SourceType Location_SourceType 150e41f4b71Sopenharmony_ci``` 151e41f4b71Sopenharmony_ci**Description** 152e41f4b71Sopenharmony_ciDefines the source of location information. 153e41f4b71Sopenharmony_ci 154e41f4b71Sopenharmony_ci**Since**: 13 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci### Location_UseScene 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci``` 160e41f4b71Sopenharmony_citypedef enum Location_UseScene Location_UseScene 161e41f4b71Sopenharmony_ci``` 162e41f4b71Sopenharmony_ci**Description** 163e41f4b71Sopenharmony_ciEnumerates use scenes in a location request. 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_ci**Since**: 13 166e41f4b71Sopenharmony_ci 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci## Enum Description 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ci 171e41f4b71Sopenharmony_ci### Location_PowerConsumptionScene 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci``` 174e41f4b71Sopenharmony_cienum Location_PowerConsumptionScene 175e41f4b71Sopenharmony_ci``` 176e41f4b71Sopenharmony_ci**Description** 177e41f4b71Sopenharmony_ciEnumerates power consumption scenarios in a location request. 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci**Since**: 13 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ci| Value| Description| 182e41f4b71Sopenharmony_ci| -------- | -------- | 183e41f4b71Sopenharmony_ci| LOCATION_HIGH_POWER_CONSUMPTION | High power consumption.<br>The mode mainly uses the GNSS positioning technology. The system uses the network positioning technology as an alternative to provide the location service for your application until the GNSS can provide stable location results.<br>During the continuous location process, the network positioning technology is used if the GNSS location result cannot be obtained within 30 seconds.<br>This policy can lead to significant hardware resource consumption and power consumption.| 184e41f4b71Sopenharmony_ci| LOCATION_LOW_POWER_CONSUMPTION | Low power consumption.<br>This mode is applicable when your application only needs the approximate location in scenarios such as when the user is browsing news, shopping online, and ordering food.<br>It mainly uses the network positioning technology and therefore the power consumption is relatively low.| 185e41f4b71Sopenharmony_ci| LOCATION_NO_POWER_CONSUMPTION | No power consumption.<br>Your application does not proactively start the location service. When responding to another application requesting the same location service, the system marks a copy of the location result to your application. | 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci### Location_ResultCode 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci``` 191e41f4b71Sopenharmony_cienum Location_ResultCode 192e41f4b71Sopenharmony_ci``` 193e41f4b71Sopenharmony_ci**Description** 194e41f4b71Sopenharmony_ciEnumerates error codes of the location service. 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**Since**: 13 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci| Value| Description| 199e41f4b71Sopenharmony_ci| -------- | -------- | 200e41f4b71Sopenharmony_ci| LOCATION_SUCCESS | Operation succeeded. | 201e41f4b71Sopenharmony_ci| LOCATION_PERMISSION_DENIED | Permission verification has failed. | 202e41f4b71Sopenharmony_ci| LOCATION_INVALID_PARAM | Parameter error.<br>Possible causes: 1. The input parameter is a null pointer. 2. The parameter value is out of the value range.| 203e41f4b71Sopenharmony_ci| LOCATION_NOT_SUPPORTED | Function not supported due to limited device capabilities. | 204e41f4b71Sopenharmony_ci| LOCATION_SERVICE_UNAVAILABLE | Location service unavailable. | 205e41f4b71Sopenharmony_ci| LOCATION_SWITCH_OFF | Location switch disabled. | 206e41f4b71Sopenharmony_ci 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci### Location_SourceType 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ci``` 211e41f4b71Sopenharmony_cienum Location_SourceType 212e41f4b71Sopenharmony_ci``` 213e41f4b71Sopenharmony_ci**Description** 214e41f4b71Sopenharmony_ciDefines the source of location information. 215e41f4b71Sopenharmony_ci 216e41f4b71Sopenharmony_ci**Since**: 13 217e41f4b71Sopenharmony_ci 218e41f4b71Sopenharmony_ci| Value| Description| 219e41f4b71Sopenharmony_ci| -------- | -------- | 220e41f4b71Sopenharmony_ci| LOCATION_SOURCE_TYPE_GNSS | GNSS positioning technology. | 221e41f4b71Sopenharmony_ci| LOCATION_SOURCE_TYPE_NETWORK | Network positioning technology. | 222e41f4b71Sopenharmony_ci| LOCATION_SOURCE_TYPE_INDOOR | Indoor high-precision positioning technology. | 223e41f4b71Sopenharmony_ci| LOCATION_SOURCE_TYPE_RTK | Outdoor high-precision positioning technology. | 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci### Location_UseScene 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci``` 229e41f4b71Sopenharmony_cienum Location_UseScene 230e41f4b71Sopenharmony_ci``` 231e41f4b71Sopenharmony_ci**Description** 232e41f4b71Sopenharmony_ciEnumerates use scenes in a location request. 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci**Since**: 13 235e41f4b71Sopenharmony_ci 236e41f4b71Sopenharmony_ci| Value| Description| 237e41f4b71Sopenharmony_ci| -------- | -------- | 238e41f4b71Sopenharmony_ci| LOCATION_USE_SCENE_NAVIGATION | Navigation scenario.<br>This option is applicable when your application needs to obtain the real-time location of a mobile device outdoors, such as navigation for driving or walking.<br>This option mainly uses the GNSS positioning technology and therefore the power consumption is relatively high.| 239e41f4b71Sopenharmony_ci| LOCATION_USE_SCENE_SPORT | Sport scenario.<br>This option is applicable when your application needs to record user trajectories, for example, the track recording function of sports applications.<br>This option mainly uses the GNSS positioning technology and therefore the power consumption is relatively high.| 240e41f4b71Sopenharmony_ci| LOCATION_USE_SCENE_TRANSPORT | Travel scenario.<br>This option is applicable to user travel scenarios, such as taxi hailing and public transportation.<br>This option mainly uses the GNSS positioning technology and therefore the power consumption is relatively high.| 241e41f4b71Sopenharmony_ci| LOCATION_USE_SCENE_DAILY_LIFE_SERVICE | Daily life services.<br>This option is applicable when your application only needs the approximate location in scenarios such as when the user is browsing news, shopping online, and ordering food.<br>It mainly uses the network positioning technology and therefore the power consumption is relatively low.| 242e41f4b71Sopenharmony_ci 243e41f4b71Sopenharmony_ci 244e41f4b71Sopenharmony_ci## Function Description 245e41f4b71Sopenharmony_ci 246e41f4b71Sopenharmony_ci 247e41f4b71Sopenharmony_ci### OH_Location_CreateRequestConfig() 248e41f4b71Sopenharmony_ci 249e41f4b71Sopenharmony_ci``` 250e41f4b71Sopenharmony_ciLocation_RequestConfig* OH_Location_CreateRequestConfig (void ) 251e41f4b71Sopenharmony_ci``` 252e41f4b71Sopenharmony_ci**Description** 253e41f4b71Sopenharmony_ciCreates a **Location_RequestConfig** instance. 254e41f4b71Sopenharmony_ci 255e41f4b71Sopenharmony_ci**Since**: 13 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci**Returns** 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ciPointer to the [Location_RequestConfig](#location_requestconfig) instance. 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ciIf **NULL** is returned, the operation has failed. The probable cause is that the application address space is full. 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ci### OH_Location_DestroyRequestConfig() 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci``` 267e41f4b71Sopenharmony_civoid OH_Location_DestroyRequestConfig (Location_RequestConfig * requestConfig) 268e41f4b71Sopenharmony_ci``` 269e41f4b71Sopenharmony_ci**Description** 270e41f4b71Sopenharmony_ciDestroys the **Location_RequestConfig** instance and reclaims the memory. 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci**Since**: 13 273e41f4b71Sopenharmony_ci 274e41f4b71Sopenharmony_ci**Parameters** 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_ci| Name| Description| 277e41f4b71Sopenharmony_ci| -------- | -------- | 278e41f4b71Sopenharmony_ci| requestConfig | Pointer to the [Location_RequestConfig](#location_requestconfig) instance.<br>The instance is created by [OH_Location_CreateRequestConfig](#oh_location_createrequestconfig).| 279e41f4b71Sopenharmony_ci 280e41f4b71Sopenharmony_ci 281e41f4b71Sopenharmony_ci### OH_Location_IsLocatingEnabled() 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci``` 284e41f4b71Sopenharmony_ciLocation_ResultCode OH_Location_IsLocatingEnabled (bool * enabled) 285e41f4b71Sopenharmony_ci``` 286e41f4b71Sopenharmony_ci**Description** 287e41f4b71Sopenharmony_ciChecks whether the location switch is enabled. 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ci**Since**: 13 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci**Parameters** 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci| Name| Description| 294e41f4b71Sopenharmony_ci| -------- | -------- | 295e41f4b71Sopenharmony_ci| enabled | Pointer of the bool type, which is used to receive the location switch status.<br>If the value is **true**, the location switch is enabled. If the value is **false**, the location switch is disabled.<br>A non-null pointer must be passed in. Otherwise, an error is returned.| 296e41f4b71Sopenharmony_ci 297e41f4b71Sopenharmony_ci**Returns** 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ciOperation result. For details, see [Location_ResultCode](#location_resultcode). 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ci**LOCAION_SUCCESS**: The location switch status is successfully queried. 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci**LOCATION_INVALID_PARAM**: The input parameter is a null pointer. 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci**LOCATION_SERVICE_UNAVAILABLE**: The location switch status fails to be queried because the location service is abnormal. 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci### OH_Location_StartLocating() 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_ci``` 311e41f4b71Sopenharmony_ciLocation_ResultCode OH_Location_StartLocating (const Location_RequestConfig * requestConfig) 312e41f4b71Sopenharmony_ci``` 313e41f4b71Sopenharmony_ci**Description** 314e41f4b71Sopenharmony_ciStarts locating and subscribes to location changes. 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci**Since**: 13 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci**Parameters** 319e41f4b71Sopenharmony_ci 320e41f4b71Sopenharmony_ci| Name| Description| 321e41f4b71Sopenharmony_ci| -------- | -------- | 322e41f4b71Sopenharmony_ci| requestConfig | Pointer to the **Location_RequestConfig** instance. This parameter is used to specify the location scene and location reporting interval.<br>For details, see [Location_RequestConfig](#location_requestconfig). You can use [OH_Location_CreateRequ·estConfig](#oh_location_createrequestconfig) to create a **Location_RequestConfig** instance.| 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ci**Returns** 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ciOperation result. For details, see [Location_ResultCode](#location_resultcode). 327e41f4b71Sopenharmony_ci 328e41f4b71Sopenharmony_ci**LOCAION_SUCCESS**: The location function is started successfully. 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci**LOCATION_INVALID_PARAM**: The input parameter **requestConfig** is a null pointer. 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci**LOCATION_PERMISSION_DENIED**: Permission verification has failed. 333e41f4b71Sopenharmony_ci 334e41f4b71Sopenharmony_ci**LOCATION_NOT_SUPPORTED**: The device does not support the location function. 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_ci**LOCATION_SERVICE_UNAVAILABLE**: The location service is abnormal. 337e41f4b71Sopenharmony_ci 338e41f4b71Sopenharmony_ci**LOCATION_SWITCH_OFF**: The location function fails to be started because the location switch is disabled. 339e41f4b71Sopenharmony_ci 340e41f4b71Sopenharmony_ci**Required Permissions** 341e41f4b71Sopenharmony_ci 342e41f4b71Sopenharmony_ciohos.permission.APPROXIMATELY_LOCATION 343e41f4b71Sopenharmony_ci 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci### OH_Location_StopLocating() 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci``` 348e41f4b71Sopenharmony_ciLocation_ResultCode OH_Location_StopLocating (const Location_RequestConfig * requestConfig) 349e41f4b71Sopenharmony_ci``` 350e41f4b71Sopenharmony_ci**Description** 351e41f4b71Sopenharmony_ciStops locating and unsubscribes from location changes. 352e41f4b71Sopenharmony_ci 353e41f4b71Sopenharmony_ci**Since**: 13 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci**Parameters** 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci| Name| Description| 358e41f4b71Sopenharmony_ci| -------- | -------- | 359e41f4b71Sopenharmony_ci| requestConfig | Pointer to the **Location_RequestConfig** instance.<br>This parameter must be the same as the pointer to **requestConfig** in [OH_Location_StartLocating](#oh_location_startlocating).<br>For details, see [Location_RequestConfig](#location_requestconfig).<br>A non-null pointer must be passed in. Otherwise, an error is returned.| 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci**Returns** 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ciOperation result. For details, see [Location_ResultCode](#location_resultcode). 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_ci**LOCAION_SUCCESS**: The location function is stopped successfully. 366e41f4b71Sopenharmony_ci 367e41f4b71Sopenharmony_ciLOCATION_INVALID_PARAM: 368e41f4b71Sopenharmony_ci- The input parameter is a null pointer. 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci- The input pointer is not the same as the pointer to **requestConfig** in [OH_Location_StartLocating](#oh_location_startlocating). 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci **LOCATION_PERMISSION_DENIED**: Permission verification has failed. 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ci **LOCATION_NOT_SUPPORTED**: The device does not support the location function. 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci **LOCATION_SERVICE_UNAVAILABLE**: The location service is abnormal. 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci **LOCATION_SWITCH_OFF**: The location switch is disabled. 379e41f4b71Sopenharmony_ci 380e41f4b71Sopenharmony_ci**Required Permissions** 381e41f4b71Sopenharmony_ci 382e41f4b71Sopenharmony_ciohos.permission.APPROXIMATELY_LOCATION 383e41f4b71Sopenharmony_ci 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci### OH_LocationInfo_GetAdditionalInfo() 386e41f4b71Sopenharmony_ci 387e41f4b71Sopenharmony_ci``` 388e41f4b71Sopenharmony_ciLocation_ResultCode OH_LocationInfo_GetAdditionalInfo (Location_Info * location, char * additionalInfo, uint32_t length ) 389e41f4b71Sopenharmony_ci``` 390e41f4b71Sopenharmony_ci**Description** 391e41f4b71Sopenharmony_ciObtains the additional information in the location information. 392e41f4b71Sopenharmony_ci 393e41f4b71Sopenharmony_ci**Since**: 13 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci**Parameters** 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_ci| Name| Description| 398e41f4b71Sopenharmony_ci| -------- | -------- | 399e41f4b71Sopenharmony_ci| location | Pointer to the [Location_Info](#location_info) instance.<br>A non-null pointer needs to be passed in. This pointer can be obtained from [Location_InfoCallback](#location_infocallback).| 400e41f4b71Sopenharmony_ci| additionalInfo | Non-null pointer of the char type. This variable is used to store the additional location information in JSON format.<br>The pointer and the corresponding memory are created by the caller. It is recommended that the memory be greater than or equal to 256 bytes.<br>If a null pointer is passed in, an error code is returned.| 401e41f4b71Sopenharmony_ci| length | Memory size of **additionalInfo**. | 402e41f4b71Sopenharmony_ci 403e41f4b71Sopenharmony_ci**Returns** 404e41f4b71Sopenharmony_ci 405e41f4b71Sopenharmony_ciOperation result. For details, see [Location_ResultCode](#location_resultcode). 406e41f4b71Sopenharmony_ci 407e41f4b71Sopenharmony_ci**LOCAION_SUCCESS**: The additional location information is successfully obtained. 408e41f4b71Sopenharmony_ci 409e41f4b71Sopenharmony_ciLOCATION_INVALID_PARAM: 410e41f4b71Sopenharmony_ci- The input parameter **location** or **additionalInfo** is a null pointer. 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci- The value of the input parameter **length** is too small, that is, the memory size of **additionalInfo** is too small, which is unable to save the complete additional information. 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci 415e41f4b71Sopenharmony_ci### OH_LocationInfo_GetBasicInfo() 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_ci``` 418e41f4b71Sopenharmony_ciLocation_BasicInfo OH_LocationInfo_GetBasicInfo (Location_Info * location) 419e41f4b71Sopenharmony_ci``` 420e41f4b71Sopenharmony_ci**Description** 421e41f4b71Sopenharmony_ciObtains basic location information. 422e41f4b71Sopenharmony_ci 423e41f4b71Sopenharmony_ci**Since**: 13 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ci**Parameters** 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci| Name| Description| 428e41f4b71Sopenharmony_ci| -------- | -------- | 429e41f4b71Sopenharmony_ci| location | Pointer to the [Location_Info](#location_info) instance.<br>A non-null pointer needs to be passed in. This pointer can be obtained from [Location_InfoCallback](#location_infocallback).| 430e41f4b71Sopenharmony_ci 431e41f4b71Sopenharmony_ci**Returns** 432e41f4b71Sopenharmony_ci 433e41f4b71Sopenharmony_ciStruct for the basic location information. For details, see [Location_BasicInfo](_location___basic_info.md). 434e41f4b71Sopenharmony_ci 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_ci### OH_LocationRequestConfig_SetCallback() 437e41f4b71Sopenharmony_ci 438e41f4b71Sopenharmony_ci``` 439e41f4b71Sopenharmony_civoid OH_LocationRequestConfig_SetCallback (Location_RequestConfig * requestConfig, Location_InfoCallback callback, void * userData ) 440e41f4b71Sopenharmony_ci``` 441e41f4b71Sopenharmony_ci**Description** 442e41f4b71Sopenharmony_ciSets the callback function. 443e41f4b71Sopenharmony_ci 444e41f4b71Sopenharmony_ci**Since**: 13 445e41f4b71Sopenharmony_ci 446e41f4b71Sopenharmony_ci**Parameters** 447e41f4b71Sopenharmony_ci 448e41f4b71Sopenharmony_ci| Name| Description| 449e41f4b71Sopenharmony_ci| -------- | -------- | 450e41f4b71Sopenharmony_ci| requestConfig | Pointer to the [Location_RequestConfig](#location_requestconfig) instance.<br>The instance is created by [OH_Location_CreateRequestConfig](#oh_location_createrequestconfig).| 451e41f4b71Sopenharmony_ci| callback | Pointer to the callback function, which is used to receive location information changes.<br>For details, see [Location_InfoCallback](#location_infocallback).| 452e41f4b71Sopenharmony_ci| userData | Pointer to the **userData** instance. This pointer is returned to the caller as an input parameter when the callback function is executed.| 453e41f4b71Sopenharmony_ci 454e41f4b71Sopenharmony_ci 455e41f4b71Sopenharmony_ci### OH_LocationRequestConfig_SetInterval() 456e41f4b71Sopenharmony_ci 457e41f4b71Sopenharmony_ci``` 458e41f4b71Sopenharmony_civoid OH_LocationRequestConfig_SetInterval (Location_RequestConfig * requestConfig, int interval ) 459e41f4b71Sopenharmony_ci``` 460e41f4b71Sopenharmony_ci**Description** 461e41f4b71Sopenharmony_ciSets the location reporting interval in the location request configuration. 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_ci**Since**: 13 464e41f4b71Sopenharmony_ci 465e41f4b71Sopenharmony_ci**Parameters** 466e41f4b71Sopenharmony_ci 467e41f4b71Sopenharmony_ci| Name| Description| 468e41f4b71Sopenharmony_ci| -------- | -------- | 469e41f4b71Sopenharmony_ci| requestConfig | Pointer to the [Location_RequestConfig](#location_requestconfig) instance.<br>The instance is created by [OH_Location_CreateRequestConfig](#oh_location_createrequestconfig).| 470e41f4b71Sopenharmony_ci| interval | Location reporting interval, in seconds. The value must be greater than or equal to **1**. The default value is **1**. | 471e41f4b71Sopenharmony_ci 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci### OH_LocationRequestConfig_SetPowerConsumptionScene() 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_ci``` 476e41f4b71Sopenharmony_civoid OH_LocationRequestConfig_SetPowerConsumptionScene (Location_RequestConfig * requestConfig, Location_PowerConsumptionScene powerConsumptionScene ) 477e41f4b71Sopenharmony_ci``` 478e41f4b71Sopenharmony_ci**Description** 479e41f4b71Sopenharmony_ciSets the power consumption scene in the location request configuration. 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci**Since**: 13 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci**Parameters** 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci| Name| Description| 486e41f4b71Sopenharmony_ci| -------- | -------- | 487e41f4b71Sopenharmony_ci| requestConfig | Pointer to the [Location_RequestConfig](#location_requestconfig) instance.<br>The instance is created by [OH_Location_CreateRequestConfig](#oh_location_createrequestconfig).| 488e41f4b71Sopenharmony_ci| powerConsumptionScene | Power consumption scene in the location request.<br>The default value is **LOCATION_LOW_POWER_CONSUMPTION**.<br>For details, see [Location_PowerConsumptionScene](#location_powerconsumptionscene).| 489e41f4b71Sopenharmony_ci 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci### OH_LocationRequestConfig_SetUseScene() 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci``` 494e41f4b71Sopenharmony_civoid OH_LocationRequestConfig_SetUseScene (Location_RequestConfig * requestConfig, Location_UseScene useScene ) 495e41f4b71Sopenharmony_ci``` 496e41f4b71Sopenharmony_ci**Description** 497e41f4b71Sopenharmony_ciSets the use scene in the location request configuration. 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ci**useScene** takes precedence over other parameters in [Location_RequestConfig](#location_requestconfig). 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ciIf **useScene** is set, **powerConsumptionScene** is invalid. 502e41f4b71Sopenharmony_ci 503e41f4b71Sopenharmony_ciOtherwise, **powerConsumptionScene** takes effect. 504e41f4b71Sopenharmony_ci 505e41f4b71Sopenharmony_ciIf neither of the two parameters is set, **useScene** is set to LOCATION_USE_SCENE_DAILY_LIFE_SERVICE by default, 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ciand **powerConsumptionScene** is invalid. 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci**Since**: 13 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_ci**Parameters** 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_ci| Name| Description| 514e41f4b71Sopenharmony_ci| -------- | -------- | 515e41f4b71Sopenharmony_ci| requestConfig | Pointer to the [Location_RequestConfig](#location_requestconfig) instance.<br>The instance is created by [OH_Location_CreateRequestConfig](#oh_location_createrequestconfig).| 516e41f4b71Sopenharmony_ci| useScene | Use scene in the location request.<br>The default value is **LOCATION_USE_SCENE_DAILY_LIFE_SERVICE**.<br>For details, see [Location_UseScene](#location_usescene).| 517