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

!23160 位置服务 ArkTS规范整改

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