diff --git a/zh-cn/application-dev/device/location-guidelines.md b/zh-cn/application-dev/device/location-guidelines.md index 06392107148d98c7a6996bd2da8f170f7da17225..e58848c2219958b50a58d156f52ac6ae85a465b8 100644 --- a/zh-cn/application-dev/device/location-guidelines.md +++ b/zh-cn/application-dev/device/location-guidelines.md @@ -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); } }); ``` diff --git a/zh-cn/application-dev/reference/apis/js-apis-geoLocationManager.md b/zh-cn/application-dev/reference/apis/js-apis-geoLocationManager.md index c79cffc135cb0c15dd6a41eb6173246f81c3fe6c..538f9c9c2db1e3cc45a2db1e0c982994460b84e3 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-geoLocationManager.md +++ b/zh-cn/application-dev/reference/apis/js-apis-geoLocationManager.md @@ -426,14 +426,15 @@ on(type: 'locationChange', request: LocationRequest, callback: Callback<Locat ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0}; - let locationChange = (location) => { + import BusinessError from "@ohos.base"; + let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0}; + let locationChange = (location:geoLocationManager.Location):void => { console.log('locationChanger: data: ' + JSON.stringify(location)); }; try { geoLocationManager.on('locationChange', requestInfo, locationChange); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -470,15 +471,16 @@ off(type: 'locationChange', callback?: Callback<Location>): void ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0}; - let locationChange = (location) => { - console.log('locationChanger: data: ' + JSON.stringify(location)); + import BusinessError from "@ohos.base"; + let requestInfo:geoLocationManager.LocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET, 'timeInterval': 1, 'distanceInterval': 0, 'maxAccuracy': 0}; + let locationChange = (location:geoLocationManager.Location):void => { + console.log('locationChanger: data: ' + JSON.stringify(location)); }; try { geoLocationManager.on('locationChange', requestInfo, locationChange); geoLocationManager.off('locationChange', locationChange); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -510,13 +512,14 @@ on(type: 'locationEnabledChange', callback: Callback<boolean>): void ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let locationEnabledChange = (state) => { + import BusinessError from "@ohos.base"; + let locationEnabledChange = (state:boolean):void => { console.log('locationEnabledChange: ' + JSON.stringify(state)); } try { geoLocationManager.on('locationEnabledChange', locationEnabledChange); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -548,14 +551,15 @@ off(type: 'locationEnabledChange', callback?: Callback<boolean>): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let locationEnabledChange = (state) => { + import BusinessError from "@ohos.base"; + let locationEnabledChange = (state:boolean):void => { console.log('locationEnabledChange: state: ' + JSON.stringify(state)); } try { geoLocationManager.on('locationEnabledChange', locationEnabledChange); geoLocationManager.off('locationEnabledChange', locationEnabledChange); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -592,14 +596,15 @@ on(type: 'cachedGnssLocationsChange', request: CachedGnssLocationsRequest, callb ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let cachedLocationsCb = (locations) => { + import BusinessError from "@ohos.base"; + let cachedLocationsCb = (locations:Array):void => { console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations)); } - let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; + let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; try { geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -635,15 +640,16 @@ off(type: 'cachedGnssLocationsChange', callback?: Callback<Array<Location& ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let cachedLocationsCb = (locations) => { + import BusinessError from "@ohos.base"; + let cachedLocationsCb = (locations:Array):void => { console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations)); } - let requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; + let requestInfo:geoLocationManager.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; try { geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb); geoLocationManager.off('cachedGnssLocationsChange'); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -678,14 +684,15 @@ on(type: 'satelliteStatusChange', callback: Callback<SatelliteStatusInfo>) ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let gnssStatusCb = (satelliteStatusInfo) => { + import BusinessError from "@ohos.base"; + let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => { console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo)); } try { geoLocationManager.on('satelliteStatusChange', gnssStatusCb); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -721,14 +728,15 @@ off(type: 'satelliteStatusChange', callback?: Callback<SatelliteStatusInfo> ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let gnssStatusCb = (satelliteStatusInfo) => { + import BusinessError from "@ohos.base"; + let gnssStatusCb = (satelliteStatusInfo:geoLocationManager.SatelliteStatusInfo):void => { console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo)); } try { geoLocationManager.on('satelliteStatusChange', gnssStatusCb); geoLocationManager.off('satelliteStatusChange', gnssStatusCb); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -764,14 +772,15 @@ on(type: 'nmeaMessage', callback: Callback<string>): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let nmeaCb = (str) => { + import BusinessError from "@ohos.base"; + let nmeaCb = (str:string):void => { console.log('nmeaMessage: ' + JSON.stringify(str)); } try { geoLocationManager.on('nmeaMessage', nmeaCb ); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -807,7 +816,8 @@ off(type: 'nmeaMessage', callback?: Callback<string>): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let nmeaCb = (str) => { + import BusinessError from "@ohos.base"; + let nmeaCb = (str:string):void => { console.log('nmeaMessage: ' + JSON.stringify(str)); } @@ -815,7 +825,7 @@ off(type: 'nmeaMessage', callback?: Callback<string>): void; geoLocationManager.on('nmeaMessage', nmeaCb); geoLocationManager.off('nmeaMessage', nmeaCb); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -853,8 +863,9 @@ on(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): vo ```ts import geoLocationManager from '@ohos.geoLocationManager'; import wantAgent from '@ohos.app.ability.wantAgent'; - - let wantAgentInfo = { + import BusinessError from "@ohos.base"; + + let wantAgentInfo:wantAgent.WantAgentInfo = { wants: [ { bundleName: "com.example.myapplication", @@ -868,11 +879,11 @@ on(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): vo }; wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { - 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); } }); ``` @@ -911,8 +922,9 @@ off(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): v ```ts import geoLocationManager from '@ohos.geoLocationManager'; import wantAgent from '@ohos.app.ability.wantAgent'; + import BusinessError from "@ohos.base"; - let wantAgentInfo = { + let wantAgentInfo:wantAgent.WantAgentInfo = { wants: [ { bundleName: "com.example.myapplication", @@ -926,12 +938,12 @@ off(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): v }; wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => { - 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); geoLocationManager.off('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); } }); ``` @@ -966,14 +978,15 @@ on(type: 'countryCodeChange', callback: Callback<CountryCode>): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let callback = (code) => { + import BusinessError from "@ohos.base"; + let callback = (code:geoLocationManager.CountryCode):void => { console.log('countryCodeChange: ' + JSON.stringify(code)); } try { geoLocationManager.on('countryCodeChange', callback); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1006,7 +1019,8 @@ off(type: 'countryCodeChange', callback?: Callback<CountryCode>): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let callback = (code) => { + import BusinessError from "@ohos.base"; + let callback = (code:geoLocationManager.CountryCode):void => { console.log('countryCodeChange: ' + JSON.stringify(code)); } @@ -1014,7 +1028,7 @@ off(type: 'countryCodeChange', callback?: Callback<CountryCode>): void; geoLocationManager.on('countryCodeChange', callback); geoLocationManager.off('countryCodeChange', callback); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1051,14 +1065,15 @@ on(type: 'locatingRequiredDataChange', config: LocatingRequiredDataConfig, callb ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let callback = (code) => { + import BusinessError from "@ohos.base"; + let callback = (code:Array):void => { console.log('locatingRequiredDataChange: ' + JSON.stringify(code)); } - let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; + let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; try { geoLocationManager.on('locatingRequiredDataChange', config, callback); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1090,15 +1105,16 @@ off(type: 'locatingRequiredDataChange', callback?: Callback<Array<Locating ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let callback = (code) => { + import BusinessError from "@ohos.base"; + let callback = (code:Array):void => { console.log('locatingRequiredDataChange: ' + JSON.stringify(code)); } - let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; + let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; try { geoLocationManager.on('locatingRequiredDataChange', config, callback); geoLocationManager.off('locatingRequiredDataChange', callback); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1134,8 +1150,9 @@ getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback<L ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0}; - let locationChange = (err, location) => { + import BusinessError from "@ohos.base"; + let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0}; + let locationChange = (err:BusinessError.BusinessError, location:geoLocationManager.Location):void => { if (err) { console.log('locationChanger: err=' + JSON.stringify(err)); } @@ -1147,7 +1164,7 @@ getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback<L try { geoLocationManager.getCurrentLocation(requestInfo, locationChange); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1181,7 +1198,8 @@ getCurrentLocation(callback: AsyncCallback<Location>): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let locationChange = (err, location) => { + import BusinessError from "@ohos.base"; + let locationChange = (err:BusinessError.BusinessError, location:geoLocationManager.Location) => { if (err) { console.log('locationChanger: err=' + JSON.stringify(err)); } @@ -1193,7 +1211,7 @@ getCurrentLocation(callback: AsyncCallback<Location>): void; try { geoLocationManager.getCurrentLocation(locationChange); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1233,16 +1251,17 @@ getCurrentLocation(request?: CurrentLocationRequest): Promise<Location> ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let requestInfo = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0}; + import BusinessError from "@ohos.base"; + let requestInfo:geoLocationManager.CurrentLocationRequest = {'priority': geoLocationManager.LocationRequestPriority.FIRST_FIX, 'scenario': geoLocationManager.LocationRequestScenario.UNSET,'maxAccuracy': 0}; try { geoLocationManager.getCurrentLocation(requestInfo).then((result) => { console.log('current location: ' + JSON.stringify(result)); }) - .catch((error) => { + .catch((error:number) => { console.log('promise, getCurrentLocation: error=' + JSON.stringify(error)); }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1277,10 +1296,11 @@ getLastLocation(): Location ```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); } ``` @@ -1311,10 +1331,11 @@ isLocationEnabled(): boolean ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { let locationEnabled = geoLocationManager.isLocationEnabled(); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1349,6 +1370,7 @@ enableLocation(callback: AsyncCallback<void>): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.enableLocation((err, data) => { if (err) { @@ -1356,7 +1378,7 @@ enableLocation(callback: AsyncCallback<void>): void; } }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1391,15 +1413,16 @@ enableLocation(): Promise<void> ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.enableLocation().then((result) => { console.log('promise, enableLocation succeed'); }) - .catch((error) => { + .catch((error:number) => { console.log('promise, enableLocation: error=' + JSON.stringify(error)); }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1427,10 +1450,11 @@ disableLocation(): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.disableLocation(); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1463,7 +1487,8 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; + import BusinessError from "@ohos.base"; + let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; try { geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { if (err) { @@ -1474,7 +1499,7 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback } }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1512,16 +1537,17 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise<Array<Ge ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; + import BusinessError from "@ohos.base"; + let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; try { geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { console.log('getAddressesFromLocation: ' + JSON.stringify(data)); }) - .catch((error) => { + .catch((error:number) => { console.log('promise, getAddressesFromLocation: error=' + JSON.stringify(error)); }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1554,7 +1580,8 @@ getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback< ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1}; + import BusinessError from "@ohos.base"; + let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1}; try { geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => { if (err) { @@ -1565,7 +1592,7 @@ getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback< } }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1603,16 +1630,17 @@ getAddressesFromLocationName(request: GeoCodeRequest): Promise<Array<GeoAd ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1}; + import BusinessError from "@ohos.base"; + let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1}; try { geoLocationManager.getAddressesFromLocationName(geocodeRequest).then((result) => { console.log('getAddressesFromLocationName: ' + JSON.stringify(result)); }) - .catch((error) => { + .catch((error:number) => { console.log('promise, getAddressesFromLocationName: error=' + JSON.stringify(error)); }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1642,10 +1670,11 @@ isGeocoderAvailable(): boolean; ```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); } ``` @@ -1679,6 +1708,7 @@ getCachedGnssLocationsSize(callback: AsyncCallback<number>): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.getCachedGnssLocationsSize((err, size) => { if (err) { @@ -1689,7 +1719,7 @@ getCachedGnssLocationsSize(callback: AsyncCallback<number>): void; } }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1723,15 +1753,16 @@ getCachedGnssLocationsSize(): Promise<number>; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.getCachedGnssLocationsSize().then((result) => { console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result)); }) - .catch((error) => { + .catch((error:number) => { console.log('promise, getCachedGnssLocationsSize: error=' + JSON.stringify(error)); }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1766,6 +1797,7 @@ flushCachedGnssLocations(callback: AsyncCallback<void>): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.flushCachedGnssLocations((err, result) => { if (err) { @@ -1773,7 +1805,7 @@ flushCachedGnssLocations(callback: AsyncCallback<void>): void; } }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1808,15 +1840,16 @@ flushCachedGnssLocations(): Promise<void>; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.flushCachedGnssLocations().then((result) => { console.log('promise, flushCachedGnssLocations success'); }) - .catch((error) => { + .catch((error:number) => { console.log('promise, flushCachedGnssLocations: error=' + JSON.stringify(error)); }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1848,7 +1881,8 @@ sendCommand(command: LocationCommand, callback: AsyncCallback<void>): void ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let requestInfo = {'scenario': 0x301, 'command': "command_1"}; + import BusinessError from "@ohos.base"; + let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"}; try { geoLocationManager.sendCommand(requestInfo, (err, result) => { if (err) { @@ -1856,7 +1890,7 @@ sendCommand(command: LocationCommand, callback: AsyncCallback<void>): void } }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1893,16 +1927,17 @@ sendCommand(command: LocationCommand): Promise<void>; ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let requestInfo = {'scenario': 0x301, 'command': "command_1"}; + import BusinessError from "@ohos.base"; + let requestInfo:geoLocationManager.LocationCommand = {'scenario': 0x301, 'command': "command_1"}; try { geoLocationManager.sendCommand(requestInfo).then((result) => { console.log('promise, sendCommand success'); }) - .catch((error) => { + .catch((error:number) => { console.log('promise, sendCommand: error=' + JSON.stringify(error)); }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1934,6 +1969,7 @@ getCountryCode(callback: AsyncCallback<CountryCode>): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.getCountryCode((err, result) => { if (err) { @@ -1944,7 +1980,7 @@ getCountryCode(callback: AsyncCallback<CountryCode>): void; } }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -1976,16 +2012,17 @@ getCountryCode(): Promise<CountryCode>; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.getCountryCode() .then((result) => { console.log('promise, getCountryCode: result=' + JSON.stringify(result)); }) - .catch((error) => { + .catch((error:number) => { console.log('promise, getCountryCode: error=' + JSON.stringify(error)); }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -2013,10 +2050,11 @@ enableLocationMock(): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.enableLocationMock(); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -2044,10 +2082,11 @@ disableLocationMock(): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.disableLocationMock(); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -2083,19 +2122,20 @@ setMockedLocations(config: LocationMockConfig): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let locations = [ + import BusinessError from "@ohos.base"; + let locations:Array = [ {"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true}, {"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true}, {"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true}, {"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true}, {"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true} ]; - let config = {"timeInterval": 5, "locations": locations}; + let config:geoLocationManager.LocationMockConfig = {"timeInterval": 5, "locations": locations}; try { geoLocationManager.enableLocationMock(); geoLocationManager.setMockedLocations(config); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -2122,10 +2162,11 @@ enableReverseGeocodingMock(): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.enableReverseGeocodingMock(); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -2152,10 +2193,11 @@ disableReverseGeocodingMock(): void; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.disableReverseGeocodingMock(); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -2190,18 +2232,19 @@ setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>): v ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let mockInfos = [ - {"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}}, - {"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}}, - {"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}}, - {"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}}, - {"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}}, + import BusinessError from "@ohos.base"; + let mockInfos:Array = [ + {"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "isFromMock": true}}, + {"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "isFromMock": true}}, + {"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "isFromMock": true}}, + {"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "isFromMock": true}}, + {"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "isFromMock": true}}, ]; try { geoLocationManager.enableReverseGeocodingMock(); geoLocationManager.setReverseGeocodingMockInfo(mockInfos); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -2240,10 +2283,11 @@ isLocationPrivacyConfirmed(type: LocationPrivacyType): boolean; ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { let isConfirmed = geoLocationManager.isLocationPrivacyConfirmed(1); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -2279,10 +2323,11 @@ setLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean) ```ts import geoLocationManager from '@ohos.geoLocationManager'; + import BusinessError from "@ohos.base"; try { geoLocationManager.setLocationPrivacyConfirmStatus(1, true); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` @@ -2323,15 +2368,16 @@ getLocatingRequiredData(config: LocatingRequiredDataConfig): Promise<Array< ```ts import geoLocationManager from '@ohos.geoLocationManager'; - let config = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; + import BusinessError from "@ohos.base"; + let config:geoLocationManager.LocatingRequiredDataConfig = {'type': 1, 'needStartScan': true, 'scanInterval': 10000}; try { geoLocationManager.getLocatingRequiredData(config).then((result) => { console.log('getLocatingRequiredData return: ' + JSON.stringify(result)); }) - .catch((error) => { + .catch((error:number) => { console.log('promise, getLocatingRequiredData: error=' + JSON.stringify(error)); }); } catch (err) { - console.error("errCode:" + err.code + ",errMessage:" + err.message); + console.error("errCode:" + (err as BusinessError.BusinessError).code + ",errMessage:" + (err as BusinessError.BusinessError).message); } ``` \ No newline at end of file diff --git a/zh-cn/application-dev/reference/apis/js-apis-geolocation.md b/zh-cn/application-dev/reference/apis/js-apis-geolocation.md index 1e7eccc4c18451a0c1521c7d0b47c344e586d8fd..9729d1682a75e37a4c557d7204ea66432da41a38 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-geolocation.md +++ b/zh-cn/application-dev/reference/apis/js-apis-geolocation.md @@ -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):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<Array<Locati ```ts import geolocation from '@ohos.geolocation'; - let cachedLocationsCb = (locations) => { + let cachedLocationsCb = (locations:Array):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<SatelliteStatusInfo>): 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<SatelliteStatusInfo>): 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<string>): 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<string>): 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<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<Location>): 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<Location> ```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<Array<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< ```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<Array<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<boolean>): 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<boolean>; ```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)); });