未验证 提交 2f157d82 编写于 作者: O openharmony_ci 提交者: Gitee

!23160 位置服务 ArkTS规范整改

Merge pull request !23160 from liuxinbing/master
......@@ -149,7 +149,7 @@
以导航场景为例,实例化方式如下:
```ts
let requestInfo = {'scenario': geoLocationManager.LocationRequestScenario.NAVIGATION, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
let requestInfo:geoLocationManager.LocationRequest = {'scenario': geoLocationManager.LocationRequestScenario.NAVIGATION, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
```
**方式二:**
......@@ -179,14 +179,14 @@
以定位精度优先策略为例,实例化方式如下:
```ts
let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.ACCURACY, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.ACCURACY, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
```
4. 实例化Callback对象,用于向系统提供位置上报的途径。
应用需要自行实现系统定义好的回调接口,并将其实例化。系统在定位成功确定设备的实时位置结果时,会通过该接口上报给应用。应用程序可以在接口的实现中完成自己的业务逻辑。
```ts
let locationChange = (location) => {
let locationChange = (location:geoLocationManager.Location):void => {
console.log('locationChanger: data: ' + JSON.stringify(location));
};
```
......@@ -209,10 +209,11 @@
```ts
import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try {
let location = geoLocationManager.getLastLocation();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
}
```
......@@ -259,10 +260,11 @@
```ts
import geoLocationManager from '@ohos.geoLocationManager';
import BusinessError from "@ohos.base";
try {
let isAvailable = geoLocationManager.isGeocoderAvailable();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
}
```
......@@ -270,7 +272,7 @@
- 调用getAddressesFromLocation,坐标转化地理位置信息。
```ts
let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
try {
geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
if (err) {
......@@ -280,7 +282,7 @@
}
});
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
}
```
......@@ -288,7 +290,7 @@
- 调用getAddressesFromLocationName位置描述转化坐标。
```ts
let geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
try {
geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => {
if (err) {
......@@ -298,7 +300,7 @@
}
});
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
}
```
......@@ -332,11 +334,12 @@
1. 使用地理围栏功能,需要有权限ohos.permission.APPROXIMATELY_LOCATION,位置权限申请的方法和步骤见[申请位置权限开发指导](#申请位置权限开发指导)
2. 导入[geoLocationManager](../reference/apis/js-apis-geoLocationManager.md)模块[wantAgent](../reference/apis/js-apis-app-ability-wantAgent.md)模块。
2. 导入[geoLocationManager](../reference/apis/js-apis-geoLocationManager.md)模块[wantAgent](../reference/apis/js-apis-app-ability-wantAgent.md)模块和[BusinessError](../reference/apis/js-apis-base.md)模块。
```ts
import geoLocationManager from '@ohos.geoLocationManager';
import wantAgent from '@ohos.app.ability.wantAgent';
import BusinessError from "@ohos.base";
```
3. 创建[WantAgentInfo](../reference/apis/js-apis-inner-wantAgent-wantAgentInfo.md)信息。
......@@ -344,10 +347,10 @@
场景一:创建拉起Ability的WantAgentInfo信息。
```ts
let wantAgentObj = null; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。
let wantAgentObj:wantAgent.WantAgentInfo|null = null; // 用于保存创建成功的wantAgent对象,后续使用其完成触发的动作。
// 通过WantAgentInfo的operationType设置动作类型
let wantAgentInfo = {
let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [
{
deviceId: '',
......@@ -368,10 +371,10 @@
场景二:创建发布[公共事件](../application-models/common-event-overview.md)的WantAgentInfo信息。
```ts
let wantAgentObj = null; // 用于保存创建成功的WantAgent对象,后续使用其完成触发的动作。
let wantAgentObj:wantAgent.WantAgentInfo|null = null; // 用于保存创建成功的WantAgent对象,后续使用其完成触发的动作。
// 通过WantAgentInfo的operationType设置动作类型
let wantAgentInfo = {
let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [
{
action: 'event_name', // 设置事件名
......@@ -397,11 +400,11 @@
}
console.info('getWantAgent success');
wantAgentObj = data;
let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
let requestInfo:geoLocationManager.GeofenceRequest = {'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
try {
geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message);
}
});
```
......
......@@ -68,8 +68,8 @@ on(type: 'locationChange', request: LocationRequest, callback: Callback<Locat
```ts
import geolocation from '@ohos.geolocation';
let requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
let locationChange = (location) => {
let requestInfo:geolocation.LocationRequest = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
let locationChange = (location:geolocation.Location):void => {
console.log('locationChanger: data: ' + JSON.stringify(location));
};
geolocation.on('locationChange', requestInfo, locationChange);
......@@ -101,8 +101,8 @@ off(type: 'locationChange', callback?: Callback<Location>): void
```ts
import geolocation from '@ohos.geolocation';
let requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
let locationChange = (location) => {
let requestInfo:geolocation.LocationRequest = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
let locationChange = (location:geolocation.Location):void => {
console.log('locationChanger: data: ' + JSON.stringify(location));
};
geolocation.on('locationChange', requestInfo, locationChange);
......@@ -135,7 +135,7 @@ on(type: 'locationServiceState', callback: Callback<boolean>): void
```ts
import geolocation from '@ohos.geolocation';
let locationServiceState = (state) => {
let locationServiceState = (state:boolean):void => {
console.log('locationServiceState: ' + JSON.stringify(state));
}
geolocation.on('locationServiceState', locationServiceState);
......@@ -167,7 +167,7 @@ off(type: 'locationServiceState', callback?: Callback<boolean>): void;
```ts
import geolocation from '@ohos.geolocation';
let locationServiceState = (state) => {
let locationServiceState = (state:boolean):void => {
console.log('locationServiceState: state: ' + JSON.stringify(state));
}
geolocation.on('locationServiceState', locationServiceState);
......@@ -202,10 +202,10 @@ on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, ca
```ts
import geolocation from '@ohos.geolocation';
let cachedLocationsCb = (locations) => {
let cachedLocationsCb = (locations:Array<geolocation.Location>):void => {
console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
}
let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
let requestInfo:geolocation.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
```
......@@ -236,10 +236,10 @@ off(type: 'cachedGnssLocationsReporting', callback?: Callback&lt;Array&lt;Locati
```ts
import geolocation from '@ohos.geolocation';
let cachedLocationsCb = (locations) => {
let cachedLocationsCb = (locations:Array<geolocation.Location>):void => {
console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
}
let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
let requestInfo:geolocation.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
geolocation.off('cachedGnssLocationsReporting');
```
......@@ -271,7 +271,7 @@ on(type: 'gnssStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;): voi
```ts
import geolocation from '@ohos.geolocation';
let gnssStatusCb = (satelliteStatusInfo) => {
let gnssStatusCb = (satelliteStatusInfo:geolocation.SatelliteStatusInfo):void => {
console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
geolocation.on('gnssStatusChange', gnssStatusCb);
......@@ -303,7 +303,7 @@ off(type: 'gnssStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;): v
```ts
import geolocation from '@ohos.geolocation';
let gnssStatusCb = (satelliteStatusInfo) => {
let gnssStatusCb = (satelliteStatusInfo:geolocation.SatelliteStatusInfo) => {
console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
geolocation.on('gnssStatusChange', gnssStatusCb);
......@@ -337,7 +337,7 @@ on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;): void;
```ts
import geolocation from '@ohos.geolocation';
let nmeaCb = (str) => {
let nmeaCb = (str:string):void => {
console.log('nmeaMessageChange: ' + JSON.stringify(str));
}
geolocation.on('nmeaMessageChange', nmeaCb );
......@@ -370,7 +370,7 @@ off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;): void;
```ts
import geolocation from '@ohos.geolocation';
let nmeaCb = (str) => {
let nmeaCb = (str:string):void => {
console.log('nmeaMessageChange: ' + JSON.stringify(str));
}
geolocation.on('nmeaMessageChange', nmeaCb);
......@@ -406,7 +406,7 @@ on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
import geolocation from '@ohos.geolocation';
import wantAgent from '@ohos.app.ability.wantAgent';
let wantAgentInfo = {
let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
......@@ -420,7 +420,7 @@ on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
};
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
let requestInfo:geolocation.GeofenceRequest = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
});
```
......@@ -454,7 +454,7 @@ off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
import geolocation from '@ohos.geolocation';
import wantAgent from '@ohos.app.ability.wantAgent';
let wantAgentInfo = {
let wantAgentInfo:wantAgent.WantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
......@@ -468,7 +468,7 @@ off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
};
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
let requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
let requestInfo:geolocation.GeofenceRequest = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
geolocation.off('fenceStatusChange', requestInfo, wantAgentObj);
});
......@@ -499,8 +499,9 @@ getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;L
```ts
import geolocation from '@ohos.geolocation';
let requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
let locationChange = (err, location) => {
import BusinessError from "@ohos.base"
let requestInfo:geolocation.CurrentLocationRequest = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
let locationChange = (err:BusinessError.BusinessError, location:geolocation.Location) => {
if (err) {
console.log('locationChanger: err=' + JSON.stringify(err));
}
......@@ -536,7 +537,8 @@ getCurrentLocation(callback: AsyncCallback&lt;Location&gt;): void
```ts
import geolocation from '@ohos.geolocation';
let locationChange = (err, location) => {
import BusinessError from "@ohos.base"
let locationChange = (err:BusinessError.BusinessError, location:geolocation.Location):void => {
if (err) {
console.log('locationChanger: err=' + JSON.stringify(err));
}
......@@ -578,7 +580,7 @@ getCurrentLocation(request?: CurrentLocationRequest): Promise&lt;Location&gt;
```ts
import geolocation from '@ohos.geolocation';
let requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
let requestInfo:geolocation.CurrentLocationRequest = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
geolocation.getCurrentLocation(requestInfo).then((result) => {
console.log('current location: ' + JSON.stringify(result));
});
......@@ -863,7 +865,7 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback
```ts
import geolocation from '@ohos.geolocation';
let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
let reverseGeocodeRequest:geolocation.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
if (err) {
console.log('getAddressesFromLocation: err=' + JSON.stringify(err));
......@@ -904,7 +906,7 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise&lt;Array&lt;Ge
```ts
import geolocation from '@ohos.geolocation';
let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
let reverseGeocodeRequest:geolocation.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
console.log('getAddressesFromLocation: ' + JSON.stringify(data));
});
......@@ -935,7 +937,7 @@ getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt
```ts
import geolocation from '@ohos.geolocation';
let geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
let geocodeRequest:geolocation.GeoCodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => {
if (err) {
console.log('getAddressesFromLocationName: err=' + JSON.stringify(err));
......@@ -976,7 +978,7 @@ getAddressesFromLocationName(request: GeoCodeRequest): Promise&lt;Array&lt;GeoAd
```ts
import geolocation from '@ohos.geolocation';
let geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
let geocodeRequest:geolocation.GeoCodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
});
......@@ -1138,7 +1140,7 @@ sendCommand(command: LocationCommand, callback: AsyncCallback&lt;boolean&gt;): v
```ts
import geolocation from '@ohos.geolocation';
let requestInfo = {'scenario': 0x301, 'command': "command_1"};
let requestInfo:geolocation.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo, (err, result) => {
if (err) {
console.log('sendCommand: err=' + JSON.stringify(err));
......@@ -1180,7 +1182,7 @@ sendCommand(command: LocationCommand): Promise&lt;boolean&gt;;
```ts
import geolocation from '@ohos.geolocation';
let requestInfo = {'scenario': 0x301, 'command': "command_1"};
let requestInfo:geolocation.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo).then((result) => {
console.log('promise, sendCommand: ' + JSON.stringify(result));
});
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册