openharmony 鸿蒙 capi-oh-location-h

2026-08-25 浏览 (1)

oh_location.h

Overview

Defines APIs for querying the location switch status, and starting and stopping location.

File to include: <LocationKit/oh_location.h>

Library: liblocation_ndk.so

System capability: SystemCapability.Location.Location.Core

Since: 13

Related module: [Location] (capi-location.md)

Summary

Functions

NameDescription
Location_ResultCode OH_Location_IsLocatingEnabled(bool* enabled)Checks whether the location switch is enabled.
Location_ResultCode OH_Location_StartLocating(const Location_RequestConfig* requestConfig)Starts the location process and subscribes to location changes.
Location_ResultCode OH_Location_StopLocating(const Location_RequestConfig* requestConfig)Stops the location process and unsubscribes from location changes.

Function Description

OH_Location_IsLocatingEnabled()

Location_ResultCode OH_Location_IsLocatingEnabled(bool* enabled)

Description

Checks whether the location switch is enabled.

Since: 13

Parameters

NameDescription
bool* enabledPointer of the bool type, which is used to receive the location switch status.
If the value is true, the location switch is enabled. If the value is false, the location switch is disabled.
A null pointer is prohibited. If a null pointer is passed in, an error is returned.

Returns

TypeDescription
Location_ResultCodeOperation result. For details, see Location_ResultCode.
LOCATION_SUCCESS if the location switch status is queried successfully;
LOCATION_INVALID_PARAM if the input parameter is a null pointer;
LOCATION_SERVICE_UNAVAILABLE if the location service is abnormal.

OH_Location_StartLocating()

Location_ResultCode OH_Location_StartLocating(const Location_RequestConfig* requestConfig)

Description

Starts the location process and subscribes to location changes.

Required permission: ohos.permission.APPROXIMATELY_LOCATION

Since: 13

Parameters

NameDescription
const Location_RequestConfig* requestConfigPointer to the Location_RequestConfig instance, which can be created using OH_Location_CreateRequestConfig. This parameter is used to specify the location scene and location reporting interval.
For details, see Location_RequestConfig.

Returns

TypeDescription
Location_ResultCodeOperation result. For details, see Location_ResultCode.
LOCATION_SUCCESS if the location process is started successfully;
LOCATION_INVALID_PARAM if the input requestConfig is a null pointer;
LOCATION_PERMISSION_DENIED if the permission verification failed;
LOCATION_NOT_SUPPORTED if the device does not support this function;
LOCATION_SERVICE_UNAVAILABLE if the location service is abnormal;
LOCATION_SWITCH_OFF if the location switch is disabled.

OH_Location_StopLocating()

Location_ResultCode OH_Location_StopLocating(const Location_RequestConfig* requestConfig)

Description

Stops the location process and unsubscribes from location changes.

Required permission: ohos.permission.APPROXIMATELY_LOCATION

Since: 13

Parameters

NameDescription
const Location_RequestConfig* requestConfigPointer to the Location_RequestConfig instance.
The value of this parameter must be the same as the pointer to requestConfig in OH_Location_StartLocating.
For details, see Location_RequestConfig.
A null pointer is prohibited. If a null pointer is passed in, an error is returned.

Returns

TypeDescription
Location_ResultCodeOperation result. For details, see Location_ResultCode.
LOCATION_SUCCESS if the location process is stopped successfully;
LOCATION_INVALID_PARAM if the input parameter is a null pointer,
2. or the input parameter is different from the pointer to requestConfig in OH_Location_StartLocating;
LOCATION_PERMISSION_DENIED if the permission verification failed;
LOCATION_NOT_SUPPORTED if the device does not support this function;
LOCATION_SERVICE_UNAVAILABLE if the location service is abnormal;
LOCATION_SWITCH_OFF if the location switch is disabled.

你可能感兴趣的鸿蒙文章

openharmony 鸿蒙 errorcode-geoLocationManager

openharmony 鸿蒙 js-apis-system-location

openharmony 鸿蒙 capi-oh-location-type-h

openharmony 鸿蒙 capi-location-location-basicinfo

openharmony 鸿蒙 Readme-EN

openharmony 鸿蒙 js-apis-geoLocationManager

openharmony 鸿蒙 js-apis-app-ability-FenceExtensionAbility

openharmony 鸿蒙 capi-location-location-requestconfig

openharmony 鸿蒙 capi-location-location-info

openharmony 鸿蒙 js-apis-app-ability-FenceExtensionContext

  • 所属分类: 后端技术
  • 本文标签: 鸿蒙 软件
  • 版权声明: 本文链接 https://seaxiang.com/blog/Z4RFJWXk