提交 78b202b4 编写于 作者: Z zengyawen

update docs

Signed-off-by: Nzengyawen <zengyawen1@huawei.com>
上级 e32fc00d
# Application Development
- [Application Development Overview](application-dev-guide.md)
- [DevEco Studio \(OpenHarmony\) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md)
- [Directory Structure](quick-start/package-structure.md)
- [ArkUI](ui/ui-arkui.md)
- [JavaScript-based Web-like Development Paradigm](ui/ui-arkui-js.md)
[Application Development Overview](application-dev-guide.md)
- [TypeScript-based Declarative Development Paradigm](ui/ui-arkui-ts.md)
- [Agent-Powered Scheduled Reminders ](background-agent-scheduled-reminder/Readme-EN.md)
- [Background Task Management ](background-task-management/Readme-EN.md)
- [Media](media/Readme-EN.md)
- [Security](security/Readme-EN.md)
- [Connectivity](connectivity/Readme-EN.md)
- [Data Management](database/Readme-EN.md)
- [USB Service](usb/Readme-EN.md)
- [DFX](dfx/Readme-EN.md)
- [WebGL](webgl/Readme-EN.md)
- [Development References](reference/Readme-EN.md)
- [JavaScript-based Web-like Development Paradigm](reference/arkui-js/Readme-EN.md)
- [TypeScript-based Declarative Development Paradigm](reference/arkui-ts/Readme-EN.md)
- [APIs](reference/apis/Readme-EN.md)
- Learn About the OpenHarmony Community
- [OpenHarmony Community](../OpenHarmony-Overview.md)
- [OpenHarmony OS](../readme)
- [Glossary ](../device-dev/glossary/glossary.md)
- [OpenHarmony Release Notes](../release-notes/Readme.md)
- Quick Start
- [Getting Started with Application Development](quick-start/Readme-EN.md)
- [Directory Structure](quick-start/package-structure.md)
- Development
- [ArkUI](ui/Readme-EN.md)
- Basic Functions
- [Agent-Powered Scheduled Reminders ](background-agent-scheduled-reminder/Readme-EN.md)
- [Background Task Management ](background-task-management/Readme-EN.md)
- [WebGL](webgl/Readme-EN.md)
- [Media](media/Readme-EN.md)
- [Security](security/Readme-EN.md)
- [Connectivity](connectivity/Readme-EN.md)
- [Data Management](database/Readme-EN.md)
- [Device](device/Readme-EN.md)
- [DFX](dfx/Readme-EN.md)
- Tools
- [DevEco Studio \(OpenHarmony\) User Guide](quick-start/deveco-studio-user-guide-for-openharmony.md)
- Hands-On Tutorials
- [Samples](https://gitee.com/openharmony/app_samples/blob/master/README.md)
- API References
- [Compent Reference (JavaScript-based Web-like Development Paradigm)](reference/arkui-js/Readme-EN.md)
- [Compent Reference (TypeScript-based Declarative Development Paradigm)](reference/arkui-ts/Readme-EN.md)
- [APIs](reference/apis/Readme-EN.md)
- Contribution
- [How to Contribute](../contribute/documentation-contribution.md)
# Device
- USB Service
- [USB Service Overview](usb-overview.md)
- [USB Service Development](usb-guidelines.md)
- Location
- [Location Overview](device-location-overview.md)
- [Obtaining Device Location Information](device-location-info.md)
- [Geocoding and Reverse Geocoding Capabilities](device-location-geocoding.md)
# Geocoding and Reverse Geocoding Capabilities
## When to Use
Describing a location using coordinates is accurate, but neither intuitive nor user-friendly.
With the geocoding and reverse geocoding capabilities, you will be able to convert geographic description into specific coordinates and vice versa. The geocoding information describes a location using several attributes, including the country, administrative region, street, house number, and address, etc.
## Available APIs
The following table describes APIs available for mutual conversion between coordinates and location information.
**Table1** APIs for geocoding and reverse geocoding
| API | Description |
| -------- | -------- |
| isGeoServiceAvailable(callback:&nbsp;AsyncCallback&lt;boolean&gt;)&nbsp;:&nbsp;void | Checks&nbsp;whether&nbsp;the&nbsp;(reverse)&nbsp;geocoding&nbsp;service&nbsp;is&nbsp;available.&nbsp;This&nbsp;function&nbsp;uses&nbsp;an&nbsp;asynchronous&nbsp;callback&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
| isGeoServiceAvailable()&nbsp;:&nbsp;Promise&lt;boolean&gt; | Checks&nbsp;whether&nbsp;the&nbsp;(reverse)&nbsp;geocoding&nbsp;service&nbsp;is&nbsp;available.&nbsp;This&nbsp;function&nbsp;uses&nbsp;a&nbsp;promise&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
| getAddressesFromLocation(request:&nbsp;ReverseGeoCodeRequest,&nbsp;callback:&nbsp;AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;)&nbsp;:&nbsp;void | Converts&nbsp;coordinates&nbsp;into&nbsp;geographic&nbsp;description&nbsp;through&nbsp;reverse&nbsp;geocoding.&nbsp;This&nbsp;function&nbsp;uses&nbsp;an&nbsp;asynchronous&nbsp;callback&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
| getAddressesFromLocation(request:&nbsp;ReverseGeoCodeRequest)&nbsp;:&nbsp;Promise&lt;Array&lt;GeoAddress&gt;&gt;; | Converts&nbsp;coordinates&nbsp;into&nbsp;geographic&nbsp;description&nbsp;through&nbsp;reverse&nbsp;geocoding.&nbsp;This&nbsp;function&nbsp;uses&nbsp;a&nbsp;promise&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
| getAddressesFromLocationName(request:&nbsp;GeoCodeRequest,&nbsp;callback:&nbsp;AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;)&nbsp;:&nbsp;void | Converts&nbsp;geographic&nbsp;description&nbsp;into&nbsp;coordinates&nbsp;through&nbsp;geocoding.&nbsp;This&nbsp;function&nbsp;uses&nbsp;an&nbsp;asynchronous&nbsp;callback&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
| getAddressesFromLocationName(request:&nbsp;GeoCodeRequest)&nbsp;:&nbsp;Promise&lt;Array&lt;GeoAddress&gt;&gt; | Converts&nbsp;geographic&nbsp;description&nbsp;into&nbsp;coordinates&nbsp;through&nbsp;geocoding.&nbsp;This&nbsp;function&nbsp;uses&nbsp;a&nbsp;promise&nbsp;to&nbsp;return&nbsp;the&nbsp;result. |
## How to Develop
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:**
> The **GeoConvert** instance needs to access backend services to obtain information. Therefore, before performing the following steps, ensure that your device is connected to the network.
1. Import the **geolocation** module by which you can implement all APIs related to the geocoding and reverse geocoding conversion capabilities.
```
import geolocation from '@ohos.geolocation';
```
2. Obtain the conversion result.
- Call **getAddressesFromLocation** to convert coordinates into geographical location information.
```
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest, (data) => {
console.log('getAddressesFromLocation: ' + JSON.stringify(data));
});
```
Your application can obtain the **GeoAddress** list that matches the specified coordinates and then read location information from it. For details, see the _API Reference_.
- Call **getAddressesFromLocationName** to convert geographic description into coordinates.
```
var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest, (data) => {
console.log('getAddressesFromLocationName: ' + JSON.stringify(data));
});
```
Your application can obtain the **GeoAddress** list that matches the specified location information and read coordinates from it. For details, see the _API Reference_.
To improve the accuracy of location results, you can set the longitude and latitude ranges in **GeoCodeRequest**.
此差异已折叠。
# Location Overview
People take their mobile devices wherever they go. Mobile devices have become a necessity in people's daily routines, whether it be for looking at the weather forecast, browsing news, hailing a taxi, navigating, or recording data from a workout. All these activities are so much associated with the location services on mobile devices.
With the location awareness capability offered by , mobile devices will be able to obtain real-time, accurate location data. Building location awareness into your application can also lead to a better contextual experience for application users.
Your application can call location-specific APIs to obtain the location information of a mobile device for offering location-based services such as drive navigation and motion track recording.
## Basic Concepts
Location awareness helps determine where a mobile device locates. The system identifies the location of a mobile device with its coordinates, and uses location technologies such as Global Navigation Satellite System (GNSS) and network positioning (for example, base station positioning or WLAN/Bluetooth positioning) to provide diverse location-based services. These advanced location technologies make it possible to obtain the accurate location of the mobile device, regardless of whether it is indoors or outdoors.
- **Coordinate**
A coordinate describes a location on the earth using the longitude and latitude in reference to the World Geodetic Coordinate System 1984.
- **GNSS positioning**
GNSS positioning locates a mobile device by using the location algorithm offered by the device chip to compute the location information provided by the Global Navigation Satellite System, for example, GPS, GLONASS, BeiDou, and Galileo. Whichever positioning system will be used during the location process depends on a hardware capability of the device.
- **Base station positioning**
Base station positioning estimates the current location of a mobile device based on the location of the resident base station in reference to the neighboring base stations. This technology provides only a low accuracy and requires access to the cellular network.
- **WLAN or Bluetooth positioning**
WLAN or Bluetooth positioning estimates the current location of a mobile device based on the locations of WLANs and Bluetooth devices that can be discovered by the device. The location accuracy of this technology depends on the distribution of fixed WLAN access points (APs) and Bluetooth devices around the device. A high density of WLAN APs and Bluetooth devices can produce a more accurate location result than base station positioning. This technology also requires access to the network.
## Working Principles
Location awareness is offered by the system as a basic service for applications. Depending on the service scenario, an application needs to initiate a location request to the system and stop the location request when the service scenario ends. In this process, the system reports the location information to the application on a real-time basis.
## Limitations and Constraints
Your application can use the location function only after the user has granted the permission and turned on the function. If the location function is off, the system will not provide the location service for any application.
Since the location information is considered sensitive, your application still needs to obtain the location access permission from the user even if the user has turned on the location function. The system will provide the location service for your application only after it has been granted the permission to access the device location information.
......@@ -31,4 +31,3 @@ You can install your OpenHarmony app in either of the following methods:
For details about how to use hdc and the command format, see [hdc\_std Usage Guidelines](https://gitee.com/openharmony/docs/blob/master/en/device-dev/subsystems/oem_subsys_toolchain_hdc_guide.md).
......@@ -46,6 +46,7 @@
- Network and Connectivity
- [WLAN](js-apis-wifi.md)
- [Bluetooth](js-apis-bluetooth.md)
- [RPC](js-apis-rpc.md)
- Device Management
- [Sensor](js-apis-sensor.md)
- [Vibrator](js-apis-vibrator.md)
......@@ -60,6 +61,7 @@
- [Display](js-apis-display.md)
- [Update](js-apis-update.md)
- [USB](js-apis-usb.md)
- [Location](js-apis-geolocation.md)
- Basic Features
- [Application Context](js-apis-basic-features-app-context.md)
- [Console Logs](js-apis-basic-features-logs.md)
......
此差异已折叠。
......@@ -7,7 +7,7 @@
- [Universal Events](js-components-common-events.md)
- [Universal Methods](js-components-common-methods.md)
- [Animation Styles](js-components-common-animation.md)
- [Gradient Styles](reference/arkui-js/js-components-common-gradient.md)
- [Gradient Styles](js-components-common-gradient.md)
- [Transition Styles](js-components-common-transition.md)
- [Media Query](js-components-common-mediaquery.md)
- [Custom Font Styles](js-components-common-customizing-font.md)
......
......@@ -81,14 +81,14 @@ You can use **$r** or **$rawfile** to create a **Resource** object. For details,
| Name| Type| Description|
| -------- | -------- | -------- |
| ResourceStr | string&nbsp;\|&nbsp;[Resource](#ResourceType) | Resource string.|
| ResourceStr | string&nbsp;\|&nbsp;[Resource](#resourcetype) | Resource string.|
## Resource Color<sup>8+</sup>
| Name| Type| Description|
| -------- | -------- | -------- |
| ResourceColor | Color&nbsp;\|&nbsp;number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](#ResourceType) | Resource color.|
| ResourceColor | Color&nbsp;\|&nbsp;number&nbsp;\|&nbsp;string&nbsp;\|&nbsp;[Resource](#resourcetype) | Resource color.|
## Custom Builder<sup>8+</sup>
......
# USB Service
- [USB Service Overview](usb-overview.md)
- [USB Service Development](usb-guidelines.md)
......@@ -13,15 +13,17 @@
- [Ability开发](ability/Readme-CN.md)
- [UI开发](ui/Readme-CN.md)
- 基础功能开发
- [后台代理提醒](background-agent-scheduled-reminder/Readme-CN.md)
- [后台任务管理](background-task-management/Readme-CN.md)
- [窗口管理](windowmanager/Readme-CN.md)
- [WebGL](webgl/Readme-CN.md)
- [媒体](media/Readme-CN.md)
- [安全](security/Readme-CN.md)
- [网络与连接](connectivity/Readme-CN.md)
- [数据管理](database/Readme-CN.md)
- [USB服务](usb/Readme-CN.md)
- [后台代理提醒](background-agent-scheduled-reminder/Readme-CN.md)
- [后台任务管理](background-task-management/Readme-CN.md)
- [设备管理](device/Readme-CN.md)
- [设备使用信息统计](device-usage-statistics/Readme-CN.md)
- [DFX](dfx/Readme-CN.md)
- [窗口管理](windowmanager/Readme-CN.md)
- 工具
- [DevEco Studio(OpenHarmony)使用指南](quick-start/deveco-studio-user-guide-for-openharmony.md)
- 示例教程
......
......@@ -36,12 +36,12 @@ import backgroundTaskManager from '@ohos.backgroundTaskManager';
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
let myReason = 'test requestSuspendDelay';
let delayInfo = backgroundTaskManager.requestSuspendDelay(myReason, () => {
console.info("Request suspension delay will time out.");
});
var id = delayInfo.requestId;console.info("requestId is: " + id);
```
......@@ -106,10 +106,10 @@ ohos.permission.KEEP_BACKGROUND_RUNNING
| function stopBackgroundRunning(context: Context, callback: AsyncCallback&lt;void&gt;): void;<br/>function stopBackgroundRunning(context: Context): Promise&lt;void&gt;; | 停止后台长时任务的运行 |
其中,wantAgent的信息详见([WantAgent](../reference/apis/js-apis-notification.md#WantAgent接口)
其中,wantAgent的信息详见([WantAgent](../reference/apis/js-apis-notification.md#WantAgent接口)
**表4** 后台模式类型
| 参数名 | id值 | 描述 |
| -------- | -------- | -------- |
| DATA_TRANSFER | 1 | 数据传输 |
......@@ -174,13 +174,13 @@ ohos.permission.KEEP_BACKGROUND_RUNNING
```js
import backgroundTaskManager from '@ohos.backgroundTaskManager';
import featureAbility from '@ohos.ability.featureAbility';
backgroundTaskManager.stopBackgroundRunning(featureAbility.getContext()).then(() => {
console.info("Operation succeeded");
}).catch((err) => {
console.error("Operation failed Cause: " + err);
});
```
## 开发实例
......
# 设备使用信息统计
- 后台任务
- [设备使用信息统计概述](device-usage-statistics-overview.md)
- [设备使用信息统计开发指导](device-usage-statistics-dev-guide.md)
\ No newline at end of file
- [设备使用信息统计概述](device-usage-statistics-overview.md)
- [设备使用信息统计开发指导](device-usage-statistics-dev-guide.md)
\ No newline at end of file
# 设备管理
- USB服务
- [USB服务开发概述](usb-overview.md)
- [USB服务开发指导](usb-guidelines.md)
- 位置
- [位置开发概述](device-location-overview.md)
- [获取设备的位置信息](device-location-info.md)
- [(逆)地理编码转化](device-location-geocoding.md)
# (逆)地理编码转化
## 场景介绍
使用坐标描述一个位置,非常准确,但是并不直观,面向用户表达并不友好。
系统向开发者提供了地理编码转化能力(将地理描述转化为具体坐标),以及逆地理编码转化能力(将坐标转化为地理描述)。其中地理编码包含多个属性来描述位置,包括国家、行政区划、街道、门牌号、地址描述等等,这样的信息更便于用户理解。
## 接口说明
进行坐标和地理编码信息的相互转化,所使用的接口说明如下。
**表1** 地理编码转化能力和逆地理编码转化能力的API功能介绍
| 接口名 | 功能描述 |
| -------- | -------- |
| isGeoServiceAvailable(callback:&nbsp;AsyncCallback&lt;boolean&gt;)&nbsp;:&nbsp;void | 判断(逆)地理编码服务状态,使用callback回调异步返回结果。 |
| isGeoServiceAvailable()&nbsp;:&nbsp;Promise&lt;boolean&gt; | 判断(逆)地理编码服务状态,使用Promise方式异步返回结果。 |
| getAddressesFromLocation(request:&nbsp;ReverseGeoCodeRequest,&nbsp;callback:&nbsp;AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;)&nbsp;:&nbsp;void | 调用逆地理编码服务,将坐标转换为地理描述,使用callback回调异步返回结果。 |
| getAddressesFromLocation(request:&nbsp;ReverseGeoCodeRequest)&nbsp;:&nbsp;Promise&lt;Array&lt;GeoAddress&gt;&gt;; | 调用逆地理编码服务,将坐标转换为地理描述,使用Promise方式异步返回结果。 |
| getAddressesFromLocationName(request:&nbsp;GeoCodeRequest,&nbsp;callback:&nbsp;AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;)&nbsp;:&nbsp;void | 调用地理编码服务,将地理描述转换为具体坐标,使用callback回调异步返回结果。 |
| getAddressesFromLocationName(request:&nbsp;GeoCodeRequest)&nbsp;:&nbsp;Promise&lt;Array&lt;GeoAddress&gt;&gt; | 调用地理编码服务,将地理描述转换为具体坐标,使用Promise方式异步返回结果。 |
## 开发步骤
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> GeoConvert需要访问后端服务,请确保设备联网,以进行信息获取。
1. 导入geolocation模块,所有与(逆)地理编码转化能力相关的功能API,都是通过该模块提供的。
```
import geolocation from '@ohos.geolocation';
```
2. 获取转化结果。
- 调用getAddressesFromLocation,坐标转化地理位置信息。
```
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest, (data) => {
console.log('getAddressesFromLocation: ' + JSON.stringify(data));
});
```
参考接口API说明,应用可以获得与此坐标匹配的GeoAddress列表,应用可以根据实际使用需求,读取相应的参数数据。
- 调用getAddressesFromLocationName位置描述转化坐标。
```
var geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest, (data) => {
console.log('getAddressesFromLocationName: ' + JSON.stringify(data));
});
```
参考接口API说明,应用可以获得与位置描述相匹配的GeoAddress列表,其中包含对应的坐标数据,请参考API使用。
如果需要查询的位置描述可能出现多地重名的请求,可以设置GeoCodeRequest,通过设置一个经纬度范围,以高效地获取期望的准确结果。
# 获取设备的位置信息
## 场景介绍
开发者可以调用OpenHarmony位置相关接口,获取设备实时位置,或者最近的历史位置。
对于位置敏感的应用业务,建议获取设备实时位置信息。如果不需要设备实时位置信息,并且希望尽可能的节省耗电,开发者可以考虑获取最近的历史位置。
## 接口说明
获取设备的位置信息,所使用的接口说明如下。
**表1** 获取位置信息API功能介绍
| 接口名 | 功能描述 |
| -------- | -------- |
| on(type:&nbsp;'locationChange',&nbsp;request:&nbsp;LocationRequest,&nbsp;callback:&nbsp;Callback&lt;Location&gt;)&nbsp;:&nbsp;void | 开启位置变化订阅,并发起定位请求。 |
| off(type:&nbsp;'locationChange',&nbsp;callback?:&nbsp;Callback&lt;Location&gt;)&nbsp;:&nbsp;void | 关闭位置变化订阅,并删除对应的定位请求。 |
| on(type:&nbsp;'locationServiceState',&nbsp;callback:&nbsp;Callback&lt;boolean&gt;)&nbsp;:&nbsp;void | 订阅位置服务状态变化。 |
| off(type:&nbsp;'locationServiceState',&nbsp;callback:&nbsp;Callback&lt;boolean&gt;)&nbsp;:&nbsp;void | 取消订阅位置服务状态变化。 |
| on(type:&nbsp;'cachedGnssLocationsReporting',&nbsp;request:&nbsp;CachedGnssLoactionsRequest,&nbsp;callback:&nbsp;Callback&lt;Array&lt;Location&gt;&gt;)&nbsp;:&nbsp;void; | 订阅缓存GNSS位置上报。 |
| off(type:&nbsp;'cachedGnssLocationsReporting',&nbsp;callback?:&nbsp;Callback&lt;Array&lt;Location&gt;&gt;)&nbsp;:&nbsp;void; | 取消订阅缓存GNSS位置上报。 |
| on(type:&nbsp;'gnssStatusChange',&nbsp;callback:&nbsp;Callback&lt;SatelliteStatusInfo&gt;)&nbsp;:&nbsp;void; | 订阅卫星状态信息更新事件。 |
| off(type:&nbsp;'gnssStatusChange',&nbsp;callback?:&nbsp;Callback&lt;SatelliteStatusInfo&gt;)&nbsp;:&nbsp;void; | 取消订阅卫星状态信息更新事件。 |
| on(type:&nbsp;'nmeaMessageChange',&nbsp;callback:&nbsp;Callback&lt;string&gt;)&nbsp;:&nbsp;void; | 订阅GNSS&nbsp;NMEA信息上报。 |
| off(type:&nbsp;'nmeaMessageChange',&nbsp;callback?:&nbsp;Callback&lt;string&gt;)&nbsp;:&nbsp;void; | 取消订阅GNSS&nbsp;NMEA信息上报。 |
| on(type:&nbsp;'fenceStatusChange',&nbsp;request:&nbsp;GeofenceRequest,&nbsp;want:&nbsp;WantAgent)&nbsp;:&nbsp;void; | 添加围栏,并订阅该围栏事件上报。 |
| off(type:&nbsp;'fenceStatusChange',&nbsp;request:&nbsp;GeofenceRequest,&nbsp;want:&nbsp;WantAgent)&nbsp;:&nbsp;void; | 删除围栏,并取消订阅该围栏事件。 |
| getCurrentLocation(request:&nbsp;CurrentLocationRequest,&nbsp;callback:&nbsp;AsyncCallback&lt;Location&gt;)&nbsp;:&nbsp;void | 获取当前位置,使用callback回调异步返回结果。 |
| getCurrentLocation(request?:&nbsp;CurrentLocationRequest)&nbsp;:&nbsp;Promise&lt;Location&gt; | 获取当前位置,使用Promise方式异步返回结果。 |
| getLastLocation(callback:&nbsp;AsyncCallback&lt;Location&gt;)&nbsp;:&nbsp;void | 获取上一次位置,使用callback回调异步返回结果。 |
| getLastLocation()&nbsp;:&nbsp;Promise&lt;Location&gt; | 获取上一次位置,使用Promise方式异步返回结果。 |
| isLocationEnabled(callback:&nbsp;AsyncCallback&lt;boolean&gt;)&nbsp;:&nbsp;void | 判断位置服务是否已经打开,使用callback回调异步返回结果。 |
| isLocationEnabled()&nbsp;:&nbsp;Promise&lt;boolean&gt; | 判断位置服务是否已经开启,使用Promise方式异步返回结果。 |
| requestEnableLocation(callback:&nbsp;AsyncCallback&lt;boolean&gt;)&nbsp;:&nbsp;void | 请求打开位置服务,使用callback回调异步返回结果。 |
| requestEnableLocation()&nbsp;:&nbsp;Promise&lt;boolean&gt; | 请求打开位置服务,使用Promise方式异步返回结果。 |
| enableLocation(callback:&nbsp;AsyncCallback&lt;boolean&gt;)&nbsp;:&nbsp;void | 打开位置服务,使用callback回调异步返回结果。 |
| enableLocation()&nbsp;:&nbsp;Promise&lt;boolean&gt; | 打开位置服务,使用Promise方式异步返回结果。 |
| disableLocation(callback:&nbsp;AsyncCallback&lt;boolean&gt;)&nbsp;:&nbsp;void | 关闭位置服务,使用callback回调异步返回结果。 |
| disableLocation()&nbsp;:&nbsp;Promise&lt;boolean&gt; | 关闭位置服务,使用Promise方式异步返回结果。 |
| getCachedGnssLocationsSize(callback:&nbsp;AsyncCallback&lt;number&gt;)&nbsp;:&nbsp;void; | 获取缓存GNSS位置的个数,使用callback回调异步返回结果。 |
| getCachedGnssLocationsSize()&nbsp;:&nbsp;Promise&lt;number&gt;; | 获取缓存GNSS位置的个数,使用Promise方式异步返回结果。 |
| flushCachedGnssLocations(callback:&nbsp;AsyncCallback&lt;boolean&gt;)&nbsp;:&nbsp;void; | 获取所有的GNSS缓存位置,并清空GNSS缓存队列,使用callback回调异步返回结果。 |
| flushCachedGnssLocations()&nbsp;:&nbsp;Promise&lt;boolean&gt;; | 获取所有的GNSS缓存位置,并清空GNSS缓存队列,使用Promise方式异步返回结果。 |
| sendCommand(command:&nbsp;LocationCommand,&nbsp;callback:&nbsp;AsyncCallback&lt;boolean&gt;)&nbsp;:&nbsp;void; | 给位置服务子系统发送扩展命令,使用callback回调异步返回结果。 |
| sendCommand(command:&nbsp;LocationCommand)&nbsp;:&nbsp;Promise&lt;boolean&gt;; | 给位置服务子系统发送扩展命令,使用Promise方式异步返回结果。 |
| isLocationPrivacyConfirmed(type&nbsp;:&nbsp;LocationPrivacyType,&nbsp;callback:&nbsp;AsyncCallback&lt;boolean&gt;)&nbsp;:&nbsp;void; | 查询用户是否同意定位服务的隐私申明,使用callback回调异步返回结果。 |
| isLocationPrivacyConfirmed(type&nbsp;:&nbsp;LocationPrivacyType,)&nbsp;:&nbsp;Promise&lt;boolean&gt;; | 查询用户是否同意定位服务的隐私申明,使用Promise方式异步返回结果。 |
| setLocationPrivacyConfirmStatus(type&nbsp;:&nbsp;LocationPrivacyType,&nbsp;isConfirmed&nbsp;:&nbsp;boolean,&nbsp;callback:&nbsp;AsyncCallback&lt;boolean&gt;)&nbsp;:&nbsp;void; | 设置并记录用户是否同意定位服务的隐私申明,使用callback回调异步返回结果。 |
| setLocationPrivacyConfirmStatus(type&nbsp;:&nbsp;LocationPrivacyType,&nbsp;isConfirmed&nbsp;:&nbsp;boolean)&nbsp;:&nbsp;Promise&lt;boolean&gt;; | 设置并记录用户是否同意定位服务的隐私申明,使用Promise方式异步返回结果。 |
## 开发步骤
1. 应用在使用系统能力前,需要检查是否已经获取用户授权访问设备位置信息。如未获得授权,可以向用户申请需要的位置权限,申请方式请参考。
系统提供的定位权限有:
- ohos.permission.LOCATION
- ohos.permission.LOCATION_IN_BACKGROUND
访问设备的位置信息,必须申请ohos.permission.LOCATION权限,并且获得用户授权。
如果应用在后台运行时也需要访问设备位置,除需要将应用声明为允许后台运行外,还必须申请ohos.permission.LOCATION_IN_BACKGROUND权限,这样应用在切入后台之后,系统可以继续上报位置信息。
开发者可以在应用config.json文件中声明所需要的权限,示例代码如下:
```
{
"module": {
"reqPermissions": [{
"name": "ohos.permission.LOCATION",
"reason": "$string:reason_description",
"usedScene": {
"ability": ["com.myapplication.LocationAbility"],
"when": "inuse"
}, {
...
}
]
}
}
```
配置字段详细说明见。
2. 导入geolocation模块,所有与基础定位能力相关的功能API,都是通过该模块提供的。
```
import geolocation from '@ohos.geolocation';
```
3. 实例化LocationRequest对象,用于告知系统该向应用提供何种类型的位置服务,以及位置结果上报的频率。
**方式一:**
为了面向开发者提供贴近其使用场景的API使用方式,系统定义了几种常见的位置能力使用场景,并针对使用场景做了适当的优化处理,应用可以直接匹配使用,简化开发复杂度。系统当前支持场景如下表所示。
```
export enum LocationRequestScenario {
UNSET = 0x300,
NAVIGATION,
TRAJECTORY_TRACKING,
CAR_HAILING,
DAILY_LIFE_SERVICE,
NO_POWER,
}
```
**表2** 定位场景类型说明
| 场景名称 | 常量定义 | 说明 |
| -------- | -------- | -------- |
| 导航场景 | NAVIGATION | 适用于在户外定位设备实时位置的场景,如车载、步行导航。在此场景下,为保证系统提供位置结果精度最优,主要使用GNSS定位技术提供定位服务,结合场景特点,在导航启动之初,用户很可能在室内、车库等遮蔽环境,GNSS技术很难提供位置服务。为解决此问题,我们会在GNSS提供稳定位置结果之前,使用系统网络定位技术,向应用提供位置服务,以在导航初始阶段提升用户体验。<br/>此场景默认以最小1秒间隔上报定位结果,使用此场景的应用必须申请ohos.permission.LOCATION权限,同时获得用户授权。 |
| 轨迹跟踪场景 | TRAJECTORY_TRACKING | 适用于记录用户位置轨迹的场景,如运动类应用记录轨迹功能。主要使用GNSS定位技术提供定位服务。<br/>此场景默认以最小1秒间隔上报定位结果,并且应用必须申请ohos.permission.LOCATION权限,同时获得用户授权。 |
| 出行约车场景 | CAR_HAILING | 适用于用户出行打车时定位当前位置的场景,如网约车类应用。<br/>此场景默认以最小1秒间隔上报定位结果,并且应用必须申请ohos.permission.LOCATION权限,同时获得用户授权。 |
| 生活服务场景 | DAILY_LIFE_SERVICE | 生活服务场景,适用于不需要定位用户精确位置的使用场景,如新闻资讯、网购、点餐类应用,做推荐、推送时定位用户大致位置即可。<br/>此场景默认以最小1秒间隔上报定位结果,并且应用至少申请ohos.permission.LOCATION权限,同时获得用户授权。 |
| 无功耗场景 | NO_POWER | 无功耗场景,适用于不需要主动启动定位业务。系统在响应其他应用启动定位业务并上报位置结果时,会同时向请求此场景的应用程序上报定位结果,当前的应用程序不产生定位功耗。<br/>此场景默认以最小1秒间隔上报定位结果,并且应用需要申请ohos.permission.LOCATION权限,同时获得用户授权。 |
以导航场景为例,实例化方式如下:
```
var requestInfo = {'scenario': 0x301, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
```
**方式二:**
如果定义的现有场景类型不能满足所需的开发场景,系统提供了基本的定位优先级策略类型。
```
export enum LocationRequestPriority {
UNSET = 0x200,
ACCURACY,
LOW_POWER,
FIRST_FIX,
}
```
**表3** 定位优先级策略类型说明:
| 策略类型 | 常量定义 | 说明 |
| -------- | -------- | -------- |
| 定位精度优先策略 | ACCURACY | 定位精度优先策略主要以GNSS定位技术为主,在开阔场景下可以提供米级的定位精度,具体性能指标依赖用户设备的定位硬件能力,但在室内等强遮蔽定位场景下,无法提供准确的位置服务。<br/>应用必须申请ohos.permission.LOCATION权限,同时获得用户授权。 |
| 快速定位优先策略 | FAST_FIRST_FIX | 快速定位优先策略会同时使用GNSS定位、基站定位和WLAN、蓝牙定位技术,以便室内和户外场景下,通过此策略都可以获得位置结果,当各种定位技术都有提供位置结果时,系统会选择其中精度较好的结果返回给应用。因为对各种定位技术同时使用,对设备的硬件资源消耗较大,功耗也较大。<br/>应用必须申请ohos.permission.LOCATION权限,同时获得用户授权。 |
| 低功耗定位优先策略 | LOW_POWER | 低功耗定位优先策略主要使用基站定位和WLAN、蓝牙定位技术,也可以同时提供室内和户外场景下的位置服务,因为其依赖周边基站、可见WLAN、蓝牙设备的分布情况,定位结果的精度波动范围较大,如果对定位结果精度要求不高,或者使用场景多在有基站、可见WLAN、蓝牙设备高密度分布的情况下,推荐使用,可以有效节省设备功耗。<br/>应用至少申请ohos.permission.LOCATION权限,同时获得用户授权。 |
以定位精度优先策略为例,实例化方式如下:
```
var requestInfo = {'priority': 0x201, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
```
4. 实例化Callback对象,用于向系统提供位置上报的途径。
应用需要自行实现系统定义好的回调接口,并将其实例化。系统在定位成功确定设备的实时位置结果时,会通过该接口上报给应用。应用程序可以在接口的实现中完成自己的业务逻辑。
```
var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
};
```
5. 启动定位。
```
geolocation.on('locationChange', requestInfo, locationChange);
```
6. (可选)结束定位。
```
geolocation.off('locationChange', locationChange);
```
如果应用使用场景不需要实时的设备位置,可以获取系统缓存的最近一次历史定位结果。
```
geolocation.getLastLocation((data) => {
console.log('getLastLocation: data: ' + JSON.stringify(data));
});
```
此接口的使用需要应用向用户申请ohos.permission.LOCATION权限。
# 位置开发概述
移动终端设备已经深入人们日常生活的方方面面,如查看所在城市的天气、新闻轶事、出行打车、旅行导航、运动记录。这些习以为常的活动,都离不开定位用户终端设备的位置。
当用户处于这些丰富的使用场景中时,系统的位置能力可以提供实时准确的位置数据。对于开发者,设计基于位置体验的服务,也可以使应用的使用体验更贴近每个用户。
当应用在实现基于设备位置的功能时,如:驾车导航,记录运动轨迹等,可以调用该模块的API接口,完成位置信息的获取。
## 基本概念
位置能力用于确定用户设备在哪里,系统使用位置坐标标示设备的位置,并用多种定位技术提供服务,如GNSS定位、基站定位、WLAN/蓝牙定位(基站定位、WLAN/蓝牙定位后续统称“网络定位技术”)。通过这些定位技术,无论用户设备在室内或是户外,都可以准确地确定设备位置。
- **坐标**
系统以1984年世界大地坐标系统为参考,使用经度、纬度数据描述地球上的一个位置。
- **GNSS定位**
基于全球导航卫星系统,包含:GPS、GLONASS、北斗、Galileo等,通过导航卫星、设备芯片提供的定位算法,来确定设备准确位置。定位过程具体使用哪些定位系统,取决于用户设备的硬件能力。
- **基站定位**
根据设备当前驻网基站和相邻基站的位置,估算设备当前位置。此定位方式的定位结果精度相对较低,并且需要设备可以访问蜂窝网络。
- **WLAN、蓝牙定位**
根据设备可搜索到的周围WLAN、蓝牙设备位置,估算设备当前位置。此定位方式的定位结果精度依赖设备周围可见的固定WLAN、蓝牙设备的分布,密度较高时,精度也相较于基站定位方式更高,同时也需要设备可以访问网络。
## 运作机制
位置能力作为系统为应用提供的一种基础服务,需要应用在所使用的业务场景,向系统主动发起请求,并在业务场景结束时,主动结束此请求,在此过程中系统会将实时的定位结果上报给应用。
## 约束与限制
使用设备的位置能力,需要用户进行确认并主动开启位置开关。如果位置开关没有开启,系统不会向任何应用提供位置服务。
设备位置信息属于用户敏感数据,所以即使用户已经开启位置开关,应用在获取设备位置前仍需向用户申请位置访问权限。在用户确认允许后,系统才会向应用提供位置服务。
......@@ -54,6 +54,7 @@
- 通信与连接
- [WLAN](js-apis-wifi.md)
- [Bluetooth](js-apis-bluetooth.md)
- [RPC通信](js-apis-rpc.md)
- 设备管理
- [传感器](js-apis-sensor.md)
- [振动](js-apis-vibrator.md)
......@@ -69,6 +70,7 @@
- [显示设备属性](js-apis-display.md)
- [升级](js-apis-update.md)
- [USB管理](js-apis-usb.md)
- [位置服务](js-apis-geolocation.md)
- 基本功能
- [应用上下文](js-apis-basic-features-app-context.md)
- [日志打印](js-apis-basic-features-logs.md)
......
......@@ -13,7 +13,7 @@ Ability运行相关信息。
通过abilityManager中getAbilityRunningInfos方法获取。
```js
import abilitymanager from '@ohos.application.abilityManager';
abilitymanager.getAbilityRunningInfos((err,data) => {
......@@ -23,14 +23,14 @@ abilitymanager.getAbilityRunningInfos((err,data) => {
## 属性
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| ability | ElementName | 是 | 否 | Ability匹配信息。<br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| pid | number | 是 | 否 | 进程ID。<br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| uid | number | 是 | 否 | 用户ID。<br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| processName | string | 是 | 否 | 进程名称。 <br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| startTime | number | 是 | 否 | Ability启动时间。<br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| abilityState | [abilityManager.AbilityState](#abilitymanager-abilitystate) | 是 | 否 | Ability状态。<br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| ability | ElementName | 是 | 否 | Ability匹配信息。<br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| pid | number | 是 | 否 | 进程ID。<br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| uid | number | 是 | 否 | 用户ID。<br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| processName | string | 是 | 否 | 进程名称。 <br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| startTime | number | 是 | 否 | Ability启动时间。<br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
| abilityState | [abilityManager.AbilityState](#abilitymanagerabilitystate) | 是 | 否 | Ability状态。<br/>**系统能力**:SystemCapability.Ability.AbilityRuntime.Core |
## abilityManager.AbilityState
......
......@@ -2531,7 +2531,7 @@ createVideoOutput(surfaceId: string, callback: AsyncCallback<VideoOutput\>): voi
| 名称 | 类型 | 必填 | 说明 |
|------------|-------------------------------|-----------|----------------------------------------------------|
| surfaceId | string | 是 | 从VideoRecorder获取的Surface ID。 |
| callback | AsyncCallback<[VideoOutput](#videootput)\> | 是 | 回调函数,用于获取VideoOutput实例。 |
| callback | AsyncCallback<[VideoOutput](#videooutput)\> | 是 | 回调函数,用于获取VideoOutput实例。 |
**示例:**
......
......@@ -13,7 +13,7 @@ Extension运行相关信息。
通过abilityManager中方法获取。
```
import abilitymanager from '@ohos.application.abilityManager';
abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => {
......@@ -24,15 +24,15 @@ abilitymanager.getExtensionRunningInfos(upperLimit, (err,data) => {
### 属性
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| 名称 | 参数类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
| extension | ElementName | 是 | 否 | Extension匹配信息。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| pid | number | 是 | 否 | 进程ID。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| uid | number | 是 | 否 | 用户ID。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| processName | string | 是 | 否 | 进程名称。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| startTime | number | 是 | 否 | Extension启动时间。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| clientPackage | Array&lt;String&gt; | 是 | 否 | 表示当期进程下的所有包名。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| type | [bundle.ExtensionAbilityType](#bundle-extensionabilitytype) | 是 | 否 | Extension类型。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| extension | ElementName | 是 | 否 | Extension匹配信息。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| pid | number | 是 | 否 | 进程ID。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| uid | number | 是 | 否 | 用户ID。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| processName | string | 是 | 否 | 进程名称。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| startTime | number | 是 | 否 | Extension启动时间。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| clientPackage | Array&lt;String&gt; | 是 | 否 | 表示当期进程下的所有包名。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
| type | [bundle.ExtensionAbilityType](#bundleextensionabilitytype) | 是 | 否 | Extension类型。<br><b>系统能力:</b>SystemCapability.Ability.AbilityRuntime.Core |
## bundle.ExtensionAbilityType
......
......@@ -259,7 +259,7 @@ Codec MIME类型枚举。
## AudioPlayer
音频播放管理类,用于管理和播放音频媒体。在调用AudioPlayer的方法前,需要先通过[createAudioPlayer()](#media.createaudioplayer)构建一个[AudioPlayer](#audioplayer)实例。
音频播放管理类,用于管理和播放音频媒体。在调用AudioPlayer的方法前,需要先通过[createAudioPlayer()](#mediacreateaudioplayer)构建一个[AudioPlayer](#audioplayer)实例。
音频播放demo可参考:[音频播放开发指导](../../media/audio-playback.md)
......
此差异已折叠。
......@@ -57,7 +57,7 @@
| [shadowColor](#shadowcolor) | &lt;color&gt; | - | 设置绘制阴影时的阴影颜色。 |
| [shadowOffsetX](#shadowoffsetx) | number | - | 设置绘制阴影时和原有对象的水平偏移值。 |
| [shadowOffsetY](#shadowoffsety) | number | - | 设置绘制阴影时和原有对象的垂直偏移值。 |
| [imageSmoothingEnabled](#imagesmoothingenabled6-)<sup>6+</sup> | boolean | true | 用于设置绘制图片时是否进行图像平滑度调整,true为启用,false为不启用。 |
| [imageSmoothingEnabled](#imagesmoothingenabled6)<sup>6+</sup> | boolean | true | 用于设置绘制图片时是否进行图像平滑度调整,true为启用,false为不启用。 |
### fillStyle
......
# USB服务
- [USB服务开发概述](usb-overview.md)
- [USB服务开发指导](usb-guidelines.md)
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册