提交 f383a67e 编写于 作者: L liu-binjun 提交者: 刘彬俊
上级 8d4c28c3
...@@ -8,8 +8,7 @@ Location services provide basic functions such as GNSS positioning, network posi ...@@ -8,8 +8,7 @@ Location services provide basic functions such as GNSS positioning, network posi
## Modules to Import ## Modules to Import
```js
```
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
``` ```
...@@ -23,7 +22,8 @@ Registers a listener for location changes with a location request initiated. ...@@ -23,7 +22,8 @@ Registers a listener for location changes with a location request initiated.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationChange** indicates a location change event.| | type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
...@@ -31,9 +31,9 @@ Registers a listener for location changes with a location request initiated. ...@@ -31,9 +31,9 @@ Registers a listener for location changes with a location request initiated.
| callback | Callback<[Location](#location)> | Yes| Callback used to return the location change event.| | callback | Callback<[Location](#location)> | Yes| Callback used to return the location change event.|
- Example **Example**
``` ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => { var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location)); console.log('locationChanger: data: ' + JSON.stringify(location));
...@@ -52,16 +52,17 @@ Unregisters the listener for location changes with the corresponding location re ...@@ -52,16 +52,17 @@ Unregisters the listener for location changes with the corresponding location re
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationChange** indicates a location change event.| | type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
| callback | Callback<[Location](#location)> | No| Callback used to return the location change event.| | callback | Callback<[Location](#location)> | No| Callback used to return the location change event.|
- Example **Example**
``` ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => { var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location)); console.log('locationChanger: data: ' + JSON.stringify(location));
...@@ -81,18 +82,19 @@ Registers a listener for location service status change events. ...@@ -81,18 +82,19 @@ Registers a listener for location service status change events.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationServiceState** indicates a location service status change event.| | type | string | Yes| Event type. The value **locationServiceState** indicates a location service status change event.|
| callback | Callback<boolean> | Yes| Callback used to return the location service status change event.| | callback | Callback<boolean> | Yes| Callback used to return the location service status change event.|
- Example **Example**
``` ```js
var locationServiceState = (state) => { var locationServiceState = (state) => {
console.log('locationServiceState: ' + state); console.log('locationServiceState: ' + JSON.stringify(state));
} }
geolocation.on('locationServiceState', locationServiceState); geolocation.on('locationServiceState', locationServiceState);
``` ```
...@@ -108,18 +110,19 @@ Unregisters the listener for location service status change events. ...@@ -108,18 +110,19 @@ Unregisters the listener for location service status change events.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationServiceState** indicates a location service status change event.| | type | string | Yes| Event type. The value **locationServiceState** indicates a location service status change event.|
| callback | Callback<boolean> | No| Callback used to return the location service status change event.| | callback | Callback<boolean> | No| Callback used to return the location service status change event.|
- Example **Example**
``` ```js
var locationServiceState = (state) => { var locationServiceState = (state) => {
console.log('locationServiceState: state: ' + state); console.log('locationServiceState: state: ' + JSON.stringify(state));
} }
geolocation.on('locationServiceState', locationServiceState); geolocation.on('locationServiceState', locationServiceState);
geolocation.off('locationServiceState', locationServiceState); geolocation.off('locationServiceState', locationServiceState);
...@@ -136,7 +139,8 @@ Registers a listener for cached GNSS location reports. ...@@ -136,7 +139,8 @@ Registers a listener for cached GNSS location reports.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **cachedGnssLocationsReporting** indicates reporting of cached GNSS locations.| | type | string | Yes| Event type. The value **cachedGnssLocationsReporting** indicates reporting of cached GNSS locations.|
...@@ -144,11 +148,11 @@ Registers a listener for cached GNSS location reports. ...@@ -144,11 +148,11 @@ Registers a listener for cached GNSS location reports.
| callback | Callback<boolean> | Yes| Callback used to return cached GNSS locations.| | callback | Callback<boolean> | Yes| Callback used to return cached GNSS locations.|
- Example **Example**
``` ```js
var cachedLocationsCb = (locations) => { var cachedLocationsCb = (locations) => {
console.log('cachedGnssLocationsReporting: locations: ' + locations); console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
} }
var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb); geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
...@@ -165,18 +169,19 @@ Unregisters the listener for cached GNSS location reports. ...@@ -165,18 +169,19 @@ Unregisters the listener for cached GNSS location reports.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **cachedGnssLocationsReporting** indicates reporting of cached GNSS locations.| | type | string | Yes| Event type. The value **cachedGnssLocationsReporting** indicates reporting of cached GNSS locations.|
| callback | Callback<boolean> | No| Callback used to return cached GNSS locations.| | callback | Callback<boolean> | No| Callback used to return cached GNSS locations.|
- Example **Example**
``` ```js
var cachedLocationsCb = (locations) => { var cachedLocationsCb = (locations) => {
console.log('cachedGnssLocationsReporting: locations: ' + locations); console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
} }
var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb); geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
...@@ -194,18 +199,19 @@ Registers a listener for GNSS satellite status change events. ...@@ -194,18 +199,19 @@ Registers a listener for GNSS satellite status change events.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **gnssStatusChange** indicates a GNSS satellite status change.| | type | string | Yes| Event type. The value **gnssStatusChange** indicates a GNSS satellite status change.|
| callback | Callback<SatelliteStatusInfo> | Yes| Callback used to return GNSS satellite status changes.| | callback | Callback<SatelliteStatusInfo> | Yes| Callback used to return GNSS satellite status changes.|
- Example **Example**
``` ```js
var gnssStatusCb = (satelliteStatusInfo) => { var gnssStatusCb = (satelliteStatusInfo) => {
console.log('gnssStatusChange: ' + satelliteStatusInfo); console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
} }
geolocation.on('gnssStatusChange', gnssStatusCb); geolocation.on('gnssStatusChange', gnssStatusCb);
``` ```
...@@ -221,17 +227,18 @@ Unregisters the listener for GNSS satellite status change events. ...@@ -221,17 +227,18 @@ Unregisters the listener for GNSS satellite status change events.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **gnssStatusChange** indicates a GNSS satellite status change.| | type | string | Yes| Event type. The value **gnssStatusChange** indicates a GNSS satellite status change.|
| callback | Callback<SatelliteStatusInfo> | No| Callback used to return GNSS satellite status changes.| | callback | Callback<SatelliteStatusInfo> | No| Callback used to return GNSS satellite status changes.|
- Example **Example**
``` ```js
var gnssStatusCb = (satelliteStatusInfo) => { var gnssStatusCb = (satelliteStatusInfo) => {
console.log('gnssStatusChange: ' + satelliteStatusInfo); console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
} }
geolocation.on('gnssStatusChange', gnssStatusCb); geolocation.on('gnssStatusChange', gnssStatusCb);
geolocation.off('gnssStatusChange', gnssStatusCb); geolocation.off('gnssStatusChange', gnssStatusCb);
...@@ -248,18 +255,19 @@ Registers a listener for GNSS NMEA message change events. ...@@ -248,18 +255,19 @@ Registers a listener for GNSS NMEA message change events.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.| | type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.|
| callback | Callback<string> | Yes| Callback used to return GNSS NMEA message changes.| | callback | Callback<string> | Yes| Callback used to return GNSS NMEA message changes.|
- Example **Example**
``` ```js
var nmeaCb = (str) => { var nmeaCb = (str) => {
console.log('nmeaMessageChange: ' + str); console.log('nmeaMessageChange: ' + JSON.stringify(str));
} }
geolocation.on('nmeaMessageChange', nmeaCb ); geolocation.on('nmeaMessageChange', nmeaCb );
``` ```
...@@ -275,18 +283,19 @@ Unregisters the listener for GNSS NMEA message change events. ...@@ -275,18 +283,19 @@ Unregisters the listener for GNSS NMEA message change events.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.| | type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.|
| callback | Callback<string> | No| Callback used to return GNSS NMEA message changes.| | callback | Callback<string> | No| Callback used to return GNSS NMEA message changes.|
- Example **Example**
``` ```js
var nmeaCb = (str) => { var nmeaCb = (str) => {
console.log('nmeaMessageChange: ' + str); console.log('nmeaMessageChange: ' + JSON.stringify(str));
} }
geolocation.on('nmeaMessageChange', nmeaCb); geolocation.on('nmeaMessageChange', nmeaCb);
geolocation.off('nmeaMessageChange', nmeaCb); geolocation.off('nmeaMessageChange', nmeaCb);
...@@ -303,7 +312,8 @@ Registers a listener for status change events of the specified geofence. ...@@ -303,7 +312,8 @@ Registers a listener for status change events of the specified geofence.
**System capability**: SystemCapability.Location.Location.Geofence **System capability**: SystemCapability.Location.Location.Geofence
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.| | type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.|
...@@ -311,52 +321,29 @@ Registers a listener for status change events of the specified geofence. ...@@ -311,52 +321,29 @@ Registers a listener for status change events of the specified geofence.
| want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.| | want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
- Example **Example**
``` ```js
import WantAgent from '@ohos.wantAgent'; import geolocation from '@ohos.geolocation';
import { OperationType, WantAgentFlags } from '@ohos.wantagent'; import wantAgent from '@ohos.wantAgent';
// WantAgent object
var wantAgent; let wantAgentInfo = {
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [ wants: [
{ {
deviceId: "deviceId", bundleName: "com.example.myapplication",
bundleName: "com.neu.setResultOnAbilityResultTest1", abilityName: "com.example.myapplication.MainAbility"
abilityName: "com.example.test.MainAbility",
action: "action1", action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} };
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}}; var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
geolocation.on('fenceStatusChange', requestInfo, wantAgent); geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
});
``` ```
...@@ -370,60 +357,91 @@ Unregisters the listener for status change events of the specified geofence. ...@@ -370,60 +357,91 @@ Unregisters the listener for status change events of the specified geofence.
**System capability**: SystemCapability.Location.Location.Geofence **System capability**: SystemCapability.Location.Location.Geofence
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.| | type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.|
| request | GeofenceRequest | Yes| Geofencing request.| | request | GeofenceRequest | Yes| Geofencing request.|
| want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.| | want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
- Example **Example**
``` ```js
import WantAgent from '@ohos.wantAgent'; import geolocation from '@ohos.geolocation';
import { OperationType, WantAgentFlags } from '@ohos.wantagent'; import wantAgent from '@ohos.wantAgent';
// WantAgent object
var wantAgent; let wantAgentInfo = {
// getWantAgent callback
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
// WantAgentInfo object
var wantAgentInfo = {
wants: [ wants: [
{ {
deviceId: "deviceId", bundleName: "com.example.myapplication",
bundleName: "com.neu.setResultOnAbilityResultTest1", abilityName: "com.example.myapplication.MainAbility"
abilityName: "com.example.test.MainAbility",
action: "action1", action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} };
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}}; var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
geolocation.on('fenceStatusChange', requestInfo, wantAgent); geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
geolocation.off('fenceStatusChange', requestInfo, wantAgent); geolocation.off('fenceStatusChange', requestInfo, wantAgentObj);
});
```
## geolocation.on('countryCodeChange')<sup>9+</sup>
on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;) : void;
Subscribe to country code information reporting events.
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is "countrycodechange", which means subscribing to the submission of country code information. |
| callback | Callback&lt;CountryCode&gt; | Yes | Callback is used to receive the country code information report. |
**Example**
```js
var callback = (code) => {
console.log('countryCodeChange: ' + JSON.stringify(code));
}
geolocation.on('countryCodeChange', callback);
```
## geolocation.off('countryCodeChange')<sup>9+</sup>
off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;) : void;
Unsubscribe from the country code to report events.
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is "countrycodechange", which means unsubscribing to the submission of country code information. |
| callback | Callback&lt;CountryCode&gt; | Yes | Callback is used to receive the country code information report. |
**Example**
```js
var callback = (code) => {
console.log('countryCodeChange: ' + JSON.stringify(code));
}
geolocation.on('countryCodeChange', callback);
geolocation.off('countryCodeChange', callback);
``` ```
...@@ -438,18 +456,24 @@ Obtains the current location. This API uses an asynchronous callback to return t ...@@ -438,18 +456,24 @@ Obtains the current location. This API uses an asynchronous callback to return t
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.| | request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.|
| callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the current location.| | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the current location.|
- Example **Example**
``` ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0}; var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
var locationChange = (err, location) => { var locationChange = (err, location) => {
console.log('locationChanger: ' + err + 'data: ' + location); if (err) {
console.log('locationChanger: err=' + JSON.stringify(err));
}
if (location) {
console.log('locationChanger: location=' + JSON.stringify(location));
}
}; };
geolocation.getCurrentLocation(requestInfo, locationChange); geolocation.getCurrentLocation(requestInfo, locationChange);
geolocation.getCurrentLocation(locationChange); geolocation.getCurrentLocation(locationChange);
...@@ -467,22 +491,24 @@ Obtains the current location. This API uses a promise to return the result. ...@@ -467,22 +491,24 @@ Obtains the current location. This API uses a promise to return the result.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.| | request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.|
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[Location](#location)&gt; | Promise used to return the current location.| | Promise&lt;[Location](#location)&gt; | Promise used to return the current location.|
- Example **Example**
``` ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0}; var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
locationEventListener.getCurrentLocation(requestInfo).then((result) => { geolocation.getCurrentLocation(requestInfo).then((result) => {
console.log('current location: ' + JSON.stringify(result)); console.log('current location: ' + JSON.stringify(result));
}); });
``` ```
...@@ -498,17 +524,23 @@ Obtains the previous location. This API uses an asynchronous callback to return ...@@ -498,17 +524,23 @@ Obtains the previous location. This API uses an asynchronous callback to return
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the previous location.| | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the previous location.|
- Example **Example**
``` ```js
geolocation.getLastLocation((err, data) => { geolocation.getLastLocation((err, data) => {
console.log('getLastLocation: ' + err + " data: " + JSON.stringify(data)); if (err) {
console.log('getLastLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('getLastLocation: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -523,15 +555,16 @@ Obtains the previous location. This API uses a promise to return the result. ...@@ -523,15 +555,16 @@ Obtains the previous location. This API uses a promise to return the result.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;[Location](#location)&gt; | Promise used to return the previous location.| | Promise&lt;[Location](#location)&gt; | Promise used to return the previous location.|
- Example **Example**
``` ```js
geolocation.getLastLocation().then((result) => { geolocation.getLastLocation().then((result) => {
console.log('getLastLocation: result: ' + JSON.stringify(result)); console.log('getLastLocation: result: ' + JSON.stringify(result));
}); });
...@@ -549,17 +582,22 @@ Checks whether the location service is enabled. This API uses an asynchronous ca ...@@ -549,17 +582,22 @@ Checks whether the location service is enabled. This API uses an asynchronous ca
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.|
**Example**
- Example ```js
```
geolocation.isLocationEnabled((err, data) => { geolocation.isLocationEnabled((err, data) => {
console.log('isLocationEnabled: ' + err + " data: " + data); if (err) {
console.log('isLocationEnabled: err=' + JSON.stringify(err));
}
if (data) {
console.log('isLocationEnabled: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -574,14 +612,15 @@ Checks whether the location service is enabled. This API uses a promise to retur ...@@ -574,14 +612,15 @@ Checks whether the location service is enabled. This API uses a promise to retur
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the location service status.| | Promise&lt;boolean&gt; | Promise used to return the location service status.|
- Example **Example**
``` ```js
geolocation.isLocationEnabled().then((result) => { geolocation.isLocationEnabled().then((result) => {
console.log('promise, isLocationEnabled: ' + result); console.log('promise, isLocationEnabled: ' + result);
}); });
...@@ -599,17 +638,22 @@ Requests to enable the location service. This API uses an asynchronous callback ...@@ -599,17 +638,22 @@ Requests to enable the location service. This API uses an asynchronous callback
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.|
**Example**
- Example ```js
```
geolocation.requestEnableLocation((err, data) => { geolocation.requestEnableLocation((err, data) => {
console.log('requestEnableLocation: ' + err + " data: " + data); if (err) {
console.log('requestEnableLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('requestEnableLocation: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -624,17 +668,17 @@ Requests to enable the location service. This API uses a promise to return the r ...@@ -624,17 +668,17 @@ Requests to enable the location service. This API uses a promise to return the r
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the location service status.| | Promise&lt;boolean&gt; | Promise used to return the location service status.|
**Example**
- Example ```js
```
geolocation.requestEnableLocation().then((result) => { geolocation.requestEnableLocation().then((result) => {
console.log('promise, requestEnableLocation: ' + result); console.log('promise, requestEnableLocation: ' + JSON.stringify(result));
}); });
``` ```
...@@ -645,23 +689,28 @@ enableLocation(callback: AsyncCallback&lt;boolean&gt;) : void; ...@@ -645,23 +689,28 @@ enableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
Enables the location service. This API uses an asynchronous callback to return the result. Enables the location service. This API uses an asynchronous callback to return the result.
This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Permission required**: ohos.permission.LOCATION **Permission required**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.|
**Example**
- Example ```js
```
geolocation.enableLocation((err, data) => { geolocation.enableLocation((err, data) => {
console.log('enableLocation: ' + err + " data: " + data); if (err) {
console.log('enableLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('enableLocation: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -672,23 +721,23 @@ enableLocation() : Promise&lt;boolean&gt; ...@@ -672,23 +721,23 @@ enableLocation() : Promise&lt;boolean&gt;
Enables the location service. This API uses a promise to return the result. Enables the location service. This API uses a promise to return the result.
This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Permission required**: ohos.permission.LOCATION **Permission required**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the location service status.| | Promise&lt;boolean&gt; | Promise used to return the location service status.|
**Example**
- Example ```js
```
geolocation.enableLocation().then((result) => { geolocation.enableLocation().then((result) => {
console.log('promise, enableLocation: ' + result); console.log('promise, enableLocation: ' + JSON.stringify(result));
}); });
``` ```
...@@ -698,23 +747,28 @@ disableLocation(callback: AsyncCallback&lt;boolean&gt;) : void; ...@@ -698,23 +747,28 @@ disableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
Disables the location service. This API uses an asynchronous callback to return the result. Disables the location service. This API uses an asynchronous callback to return the result.
This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Permission required**: ohos.permission.LOCATION **Permission required**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.|
**Example**
- Example ```js
```
geolocation.disableLocation((err, data) => { geolocation.disableLocation((err, data) => {
console.log('disableLocation: ' + err + " data: " + data); if (err) {
console.log('disableLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('disableLocation: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -725,23 +779,23 @@ disableLocation() : Promise&lt;boolean&gt; ...@@ -725,23 +779,23 @@ disableLocation() : Promise&lt;boolean&gt;
Disables the location service. This API uses a promise to return the result. Disables the location service. This API uses a promise to return the result.
This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Permission required**: ohos.permission.LOCATION **Permission required**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the location service status.| | Promise&lt;boolean&gt; | Promise used to return the location service status.|
**Example**
- Example ```js
```
geolocation.disableLocation().then((result) => { geolocation.disableLocation().then((result) => {
console.log('promise, disableLocation: ' + result); console.log('promise, disableLocation: ' + JSON.stringify(result));
}); });
``` ```
...@@ -755,17 +809,22 @@ Checks whether the (reverse) geocoding service is available. This API uses an as ...@@ -755,17 +809,22 @@ Checks whether the (reverse) geocoding service is available. This API uses an as
**System capability**: SystemCapability.Location.Location.Geocoder **System capability**: SystemCapability.Location.Location.Geocoder
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the (reverse) geocoding service status.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the (reverse) geocoding service status.|
**Example**
- Example ```js
```
geolocation.isGeoServiceAvailable((err, data) => { geolocation.isGeoServiceAvailable((err, data) => {
console.log('isGeoServiceAvailable: ' + err + " data: " + data); if (err) {
console.log('isGeoServiceAvailable: err=' + JSON.stringify(err));
}
if (data) {
console.log('isGeoServiceAvailable: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -780,22 +839,21 @@ Checks whether the (reverse) geocoding service is available. This API uses a pro ...@@ -780,22 +839,21 @@ Checks whether the (reverse) geocoding service is available. This API uses a pro
**System capability**: SystemCapability.Location.Location.Geocoder **System capability**: SystemCapability.Location.Location.Geocoder
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the (reverse) geocoding service status.| | Promise&lt;boolean&gt; | Promise used to return the (reverse) geocoding service status.|
**Example**
- Example ```js
```
geolocation.isGeoServiceAvailable().then((result) => { geolocation.isGeoServiceAvailable().then((result) => {
console.log('promise, isGeoServiceAvailable: ' + result); console.log('promise, isGeoServiceAvailable: ' + JSON.stringify(result));
}); });
``` ```
## geolocation.getAddressesFromLocation ## geolocation.getAddressesFromLocation
getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;) : void getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;) : void
...@@ -806,18 +864,24 @@ Converts coordinates into geographic description through reverse geocoding. This ...@@ -806,18 +864,24 @@ Converts coordinates into geographic description through reverse geocoding. This
**System capability**: SystemCapability.Location.Location.Geocoder **System capability**: SystemCapability.Location.Location.Geocoder
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.| | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
| callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the reverse geocoding result.| | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the reverse geocoding result.|
- Example **Example**
``` ```js
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
console.log('getAddressesFromLocation: ' + err + " data: " + JSON.stringify(data)); if (err) {
console.log('getAddressesFromLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('getAddressesFromLocation: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -832,19 +896,21 @@ Converts coordinates into geographic description through reverse geocoding. This ...@@ -832,19 +896,21 @@ Converts coordinates into geographic description through reverse geocoding. This
**System capability**: SystemCapability.Location.Location.Geocoder **System capability**: SystemCapability.Location.Location.Geocoder
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.| | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Promise used to return the reverse geocoding result.| | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Promise used to return the reverse geocoding result.|
- Example **Example**
``` ```js
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; var 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));
...@@ -862,19 +928,24 @@ Converts geographic description into coordinates through geocoding. This API use ...@@ -862,19 +928,24 @@ Converts geographic description into coordinates through geocoding. This API use
**System capability**: SystemCapability.Location.Location.Geocoder **System capability**: SystemCapability.Location.Location.Geocoder
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.| | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
| callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the geocoding result.| | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the geocoding result.|
**Example**
- Example ```js
```
var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => { geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => {
console.log('getAddressesFromLocationName: ' + err + " data: " + JSON.stringify(data)); if (err) {
console.log('getAddressesFromLocationName: err=' + JSON.stringify(err));
}
if (data) {
console.log('getAddressesFromLocationName: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -889,19 +960,21 @@ Converts geographic description into coordinates through geocoding. This API use ...@@ -889,19 +960,21 @@ Converts geographic description into coordinates through geocoding. This API use
**System capability**: SystemCapability.Location.Location.Geocoder **System capability**: SystemCapability.Location.Location.Geocoder
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.| | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Callback used to return the geocoding result.| | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Callback used to return the geocoding result.|
- Example **Example**
``` ```js
var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
console.log('getAddressesFromLocationName: ' + JSON.stringify(result)); console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
...@@ -909,7 +982,6 @@ Converts geographic description into coordinates through geocoding. This API use ...@@ -909,7 +982,6 @@ Converts geographic description into coordinates through geocoding. This API use
``` ```
## geolocation.getCachedGnssLocationsSize<sup>8+</sup> ## geolocation.getCachedGnssLocationsSize<sup>8+</sup>
getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;) : void; getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;) : void;
...@@ -920,16 +992,22 @@ Obtains the number of cached GNSS locations. ...@@ -920,16 +992,22 @@ Obtains the number of cached GNSS locations.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of cached GNSS locations. | | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of cached GNSS locations. |
- Example **Example**
``` ```js
geolocation.getCachedGnssLocationsSize((err, size) => { geolocation.getCachedGnssLocationsSize((err, size) => {
console.log('getCachedGnssLocationsSize: err:' + err + " size: " + size); if (err) {
console.log('getCachedGnssLocationsSize: err=' + JSON.stringify(err));
}
if (size) {
console.log('getCachedGnssLocationsSize: size=' + JSON.stringify(size));
}
}); });
``` ```
...@@ -944,16 +1022,17 @@ Obtains the number of cached GNSS locations. ...@@ -944,16 +1022,17 @@ Obtains the number of cached GNSS locations.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | Promise used to return the number of cached GNSS locations.| | Promise&lt;number&gt; | Promise used to return the number of cached GNSS locations.|
- Example **Example**
``` ```js
geolocation.getCachedGnssLocationsSize().then((result) => { geolocation.getCachedGnssLocationsSize().then((result) => {
console.log('promise, getCachedGnssLocationsSize: ' + result); console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
}); });
``` ```
...@@ -968,16 +1047,22 @@ Obtains all cached GNSS locations and clears the GNSS cache queue. ...@@ -968,16 +1047,22 @@ Obtains all cached GNSS locations and clears the GNSS cache queue.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the operation result.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the operation result.|
- Example **Example**
``` ```js
geolocation.flushCachedGnssLocations((err, result) => { geolocation.flushCachedGnssLocations((err, result) => {
console.log('flushCachedGnssLocations: err:' + err + " result: " + result); if (err) {
console.log('flushCachedGnssLocations: err=' + JSON.stringify(err));
}
if (result) {
console.log('flushCachedGnssLocations: result=' + JSON.stringify(result));
}
}); });
``` ```
...@@ -992,16 +1077,17 @@ Obtains all cached GNSS locations and clears the GNSS cache queue. ...@@ -992,16 +1077,17 @@ Obtains all cached GNSS locations and clears the GNSS cache queue.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Promise used to return the operation result.| | Promise&lt;boolean&gt; | Promise used to return the operation result.|
- Example **Example**
``` ```js
geolocation.flushCachedGnssLocations().then((result) => { geolocation.flushCachedGnssLocations().then((result) => {
console.log('promise, flushCachedGnssLocations: ' + result); console.log('promise, flushCachedGnssLocations: ' + JSON.stringify(result));
}); });
``` ```
...@@ -1016,18 +1102,24 @@ Sends an extended command to the location subsystem. This API can only be called ...@@ -1016,18 +1102,24 @@ Sends an extended command to the location subsystem. This API can only be called
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| command | LocationCommand | Yes| Extended command (string) to be sent.| | command | LocationCommand | Yes| Extended command (string) to be sent.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the operation result.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the operation result.|
- Example **Example**
``` ```js
var requestInfo = {'scenario': 0x301, 'command': "command_1"}; var requestInfo = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo, (err, result) => { geolocation.sendCommand(requestInfo, (err, result) => {
console.log('sendCommand: err:' + err + " result: " + result); if (err) {
console.log('sendCommand: err=' + JSON.stringify(err));
}
if (result) {
console.log('sendCommand: result=' + JSON.stringify(result));
}
}); });
``` ```
...@@ -1042,22 +1134,24 @@ Sends an extended command to the location subsystem. This API can only be called ...@@ -1042,22 +1134,24 @@ Sends an extended command to the location subsystem. This API can only be called
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| command | LocationCommand | Yes| Extended command (string) to be sent.| | command | LocationCommand | Yes| Extended command (string) to be sent.|
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Callback used to return the operation result.| | Promise&lt;boolean&gt; | Callback used to return the operation result.|
- Example **Example**
``` ```js
var requestInfo = {'scenario': 0x301, 'command': "command_1"}; var requestInfo = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo).then((result) => { geolocation.sendCommand(requestInfo).then((result) => {
console.log('promise, sendCommand: ' + result); console.log('promise, sendCommand: ' + JSON.stringify(result));
}); });
``` ```
...@@ -1068,23 +1162,29 @@ isLocationPrivacyConfirmed(type : LocationPrivacyType, callback: AsyncCallback&l ...@@ -1068,23 +1162,29 @@ isLocationPrivacyConfirmed(type : LocationPrivacyType, callback: AsyncCallback&l
Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications. Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications.
This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Permission required**: ohos.permission.LOCATION **Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.| | type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
- Example **Example**
``` ```js
geolocation.isLocationPrivacyConfirmed(1, (err, result) => { geolocation.isLocationPrivacyConfirmed(1, (err, result) => {
console.log('isLocationPrivacyConfirmed: err:' + err + " result: " + result); if (err) {
console.log('isLocationPrivacyConfirmed: err=' + JSON.stringify(err));
}
if (result) {
console.log('isLocationPrivacyConfirmed: result=' + JSON.stringify(result));
}
}); });
``` ```
...@@ -1095,27 +1195,29 @@ isLocationPrivacyConfirmed(type : LocationPrivacyType,) : Promise&lt;boolean&gt; ...@@ -1095,27 +1195,29 @@ isLocationPrivacyConfirmed(type : LocationPrivacyType,) : Promise&lt;boolean&gt;
Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications. Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications.
This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Permission required**: ohos.permission.LOCATION **Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.| | type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.|
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Callback used to return the result, which indicates whether the user agrees with the privacy statement.| | Promise&lt;boolean&gt; | Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
- Example **Example**
``` ```js
geolocation.isLocationPrivacyConfirmed(1).then((result) => { geolocation.isLocationPrivacyConfirmed(1).then((result) => {
console.log('promise, isLocationPrivacyConfirmed: ' + result); console.log('promise, isLocationPrivacyConfirmed: ' + JSON.stringify(result));
}); });
``` ```
...@@ -1126,24 +1228,30 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed: boolean ...@@ -1126,24 +1228,30 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed: boolean
Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications. Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications.
This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Permission required**: ohos.permission.LOCATION **Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.| | type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.|
| isConfirmed | boolean | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.| | isConfirmed | boolean | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the operation result.| | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the operation result.|
- Example **Example**
``` ```js
geolocation.setLocationPrivacyConfirmStatus(1, true, (err, result) => { geolocation.setLocationPrivacyConfirmStatus(1, true, (err, result) => {
console.log('isLocationPrivacyConfirmed: err:' + err + " result: " + result); if (err) {
console.log('setLocationPrivacyConfirmStatus: err=' + JSON.stringify(err));
}
if (result) {
console.log('setLocationPrivacyConfirmStatus: result=' + JSON.stringify(result));
}
}); });
``` ```
...@@ -1154,32 +1262,540 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolea ...@@ -1154,32 +1262,540 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolea
Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications. Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications.
This is a system API and cannot be called by third-party applications. **System API**: This is a system API and cannot be called by third-party applications.
**Permission required**: ohos.permission.LOCATION **Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
- Parameters **Parameters**
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.| | type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.|
| isConfirmed | boolean | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.| | isConfirmed | boolean | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
- Return value **Return value**
| Name| Description| | Name| Description|
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | Callback used to return the operation result.| | Promise&lt;boolean&gt; | Callback used to return the operation result.|
- Example **Example**
``` ```js
geolocation.setLocationPrivacyConfirmStatus(1, true).then((result) => { geolocation.setLocationPrivacyConfirmStatus(1, true).then((result) => {
console.log('promise, setLocationPrivacyConfirmStatus: ' + result); console.log('promise, setLocationPrivacyConfirmStatus: ' + JSON.stringify(result));
}); });
``` ```
## geolocation.getCountryCode<sup>9+</sup>
getCountryCode(callback: AsyncCallback&lt;CountryCode&gt;) : void;
Query the current country code.
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;CountryCode&gt; | Yes | Callback is used to receive the country code. |
**Example**:
```js
geolocation.getCountryCode((err, result) => {
if (err) {
console.log('getCountryCode: err=' + JSON.stringify(err));
}
if (result) {
console.log('getCountryCode: result=' + JSON.stringify(result));
}
});
```
## geolocation.getCountryCode<sup>9+</sup>
getCountryCode() : Promise&lt;CountryCode&gt;;
Query the current country code.
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
None
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;CountryCode&gt; | return country code. |
**Example**:
```js
geolocation.getCountryCode()
.then((result) => {
console.log('promise, getCountryCode: result=' + JSON.stringify(result));
})
.catch((error) => {
console.log('promise, getCountryCode: error=' + JSON.stringify(error));
});
```
## geolocation.enableLocationMock<sup>9+</sup>
enableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback&lt;void&gt;) : void;
Enable the position simulation function of a scene, and only one scene can be enabled at the same time.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | No | Indicates under what scenario the position simulation function is enabled. |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var request = {"scenario": 0x0301};
geolocation.enableLocationMock(request, (err, result) => {
if (err) {
console.log('enableLocationMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('enableLocationMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.enableLocationMock<sup>9+</sup>
enableLocationMock(scenario?: LocationRequestScenario) : Promise&lt;void&gt;;
Enable the position simulation function of a scene, and only one scene can be enabled at the same time.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | No | Indicates which scene's position simulation function is enabled. If this parameter is not carried, it means that the position simulation function of all scenes is enabled. |
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var request = {"scenario": 0x0301};
geolocation.enableLocationMock(request)
.then((result) => {
if (result) {
console.log('promise, enableLocationMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, enableLocationMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.disableLocationMock<sup>9+</sup>
disableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback&lt;void&gt;) : void;
To disable the position simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | No | Indicates to disable the position simulation function of a scene. If this parameter is not carried, it means to disable the position simulation function of all scenes. |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var request = {"scenario": 0x0301};
geolocation.disableLocationMock(request, (err, result) => {
if (err) {
console.log('disableLocationMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('disableLocationMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.disableLocationMock<sup>9+</sup>
disableLocationMock(scenario?: LocationRequestScenario) : Promise&lt;void&gt;;
To disable the position simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | No | Indicates to disable the position simulation function of a scene. If this parameter is not carried, it means to disable the position simulation function of all scenes. |
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr, otherwise it will return an error message |
**Example**:
```js
var request = {"scenario": 0x0301};
geolocation.disableLocationMock(request)
.then((result) => {
if (result) {
console.log('promise, disableLocationMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, disableLocationMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.setMockedLocations<sup>9+</sup>
setMockedLocations(config: LocationMockConfig, callback: AsyncCallback&lt;void&gt;) : void;
Set the simulated location information, and then report the simulated location at the time interval carried in the interface.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | LocationMockConfig | Yes | Indicates the configuration parameters of location simulation, including the time interval of simulation location reporting and the array of simulation locations. |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var locations = [
{"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}
];
var config = {"timeInterval": 5, "locations": locations};
geolocation.setMockedLocations(config, (err, data) => {
if (err) {
console.log('setMockedLocations: err=' + JSON.stringify(err));
}
if (data) {
console.log('setMockedLocations: data=' + JSON.stringify(data));
}
});
```
## geolocation.setMockedLocations<sup>9+</sup>
setMockedLocations(config: LocationMockConfig) : Promise&lt;void&gt;;
Set the simulated location information, and then report the simulated location at the time interval carried in the interface.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | LocationMockConfig | Yes | Indicates the configuration parameters of location simulation, including the time interval of simulation location reporting and the array of simulation locations. |
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var locations = [
{"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}
];
var config = {"timeInterval": 5, "locations":locations};
geolocation.setMockedLocations(config)
.then((result) => {
if (result) {
console.log('promise, setMockedLocations: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, setMockedLocations: error=' + JSON.stringify(error));
}
});
```
## geolocation.enableReverseGeocodingMock<sup>9+</sup>
enableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;) : void;
Enable reverse geocoding simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
geolocation.enableReverseGeocodingMock((err, data) => {
if (err) {
console.log('enableReverseGeocodingMock: err=' + JSON.stringify(err));
}
if (data) {
console.log('enableReverseGeocodingMock: data=' + JSON.stringify(data));
}
});
```
## geolocation.enableReverseGeocodingMock<sup>9+</sup>
enableReverseGeocodingMock() : Promise&lt;void&gt;;
Enable reverse geocoding simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**:
None
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
geolocation.enableReverseGeocodingMock()
.then((result) => {
if (result) {
console.log('promise, enableReverseGeocodingMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, enableReverseGeocodingMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.disableReverseGeocodingMock<sup>9+</sup>
disableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;) : void;
Disable reverse geocoding simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**:
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message |
**Example**:
```js
geolocation.disableReverseGeocodingMock((err, result) => {
if (err) {
console.log('disableReverseGeocodingMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('disableReverseGeocodingMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.disableReverseGeocodingMock<sup>9+</sup>
disableReverseGeocodingMock() : Promise&lt;void&gt;;
Disable reverse geocoding simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**:
None
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
geolocation.disableReverseGeocodingMock()
.then((result) => {
if (result) {
console.log('promise, disableReverseGeocodingMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, disableReverseGeocodingMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.setReverseGeocodingMockInfo<sup>9+</sup>
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;, callback: AsyncCallback&lt;void&gt;) : void;
Set the configuration information of the reverse geocoding simulation function, including the corresponding relationship between location and place name. If the location information is in the configuration information during the subsequent reverse geocoding query, the corresponding place name will be returned.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;ReverseGeocodingMockInfo&gt; | Yes | An array of configuration parameters indicating the inverse geocoding simulation function. The configuration parameters of the inverse geocoding simulation function include a location and a place name. |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var mockInfos = [
{"location": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geolocation.setReverseGeocodingMockInfo(mockInfos, (err, data) => {
if (err) {
console.log('promise, setReverseGeocodingMockInfo, err:' + JSON.stringify(err));
}
if (data) {
console.log('promise, setReverseGeocodingMockInfo, data:' + JSON.stringify(data));
}
});
```
## geolocation.setReverseGeocodingMockInfo<sup>9+</sup>
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;) : Promise&lt;void&gt;;
Set the configuration information of the reverse geocoding simulation function, including the corresponding relationship between location and place name. If the location information is in the configuration information during the subsequent reverse geocoding query, the corresponding place name will be returned.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;ReverseGeocodingMockInfo&gt; | Yes | An array of configuration parameters indicating the inverse geocoding simulation function. The configuration parameters of the inverse geocoding simulation function include a location and a place name. |
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var mockInfos = [
{"location": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geolocation.setReverseGeocodingMockInfo(mockInfos)
.then((result) => {
if (result) {
console.log('promise, setReverseGeocodingMockInfo: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, setReverseGeocodingMockInfo: error=' + JSON.stringify(error));
}
});
```
## LocationRequestPriority ## LocationRequestPriority
...@@ -1225,13 +1841,15 @@ Enumerates error codes of the location service. ...@@ -1225,13 +1841,15 @@ Enumerates error codes of the location service.
| Name| Default Value| Description| | Name| Default Value| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| INPUT_PARAMS_ERROR | 101 | Incorrect input parameters.| | NOT_SUPPORTED<sup>9+</sup> | 100 | Indicates that the interface function is not supported. |
| REVERSE_GEOCODE_ERROR | 102 | Failed to call the reverse geocoding API.| | INPUT_PARAMS_ERROR<sup>7+</sup> | 101 | Incorrect input parameters.|
| GEOCODE_ERROR | 103 | Failed to call the geocoding API.| | REVERSE_GEOCODE_ERROR<sup>7+</sup> | 102 | Failed to call the reverse geocoding API.|
| LOCATOR_ERROR | 104 | Failed to obtain the location.| | GEOCODE_ERROR<sup>7+</sup> | 103 | Failed to call the geocoding API.|
| LOCATION_SWITCH_ERROR | 105 | Failed to change the location service switch.| | LOCATOR_ERROR<sup>7+</sup> | 104 | Failed to obtain the location.|
| LAST_KNOWN_LOCATION_ERROR | 106 | Failed to obtain the previous location.| | LOCATION_SWITCH_ERROR<sup>7+</sup> | 105 | Failed to change the location service switch.|
| LOCATION_REQUEST_TIMEOUT_ERROR | 107 | Failed to obtain the location within the specified time.| | LAST_KNOWN_LOCATION_ERROR<sup>7+</sup> | 106 | Failed to obtain the previous location.|
| LOCATION_REQUEST_TIMEOUT_ERROR<sup>7+</sup> | 107 | Failed to obtain the location within the specified time.|
| QUERY_COUNTRY_CODE_ERROR<sup>9+</sup> | 108 | Indicates that the country code query failed. |
## ReverseGeoCodeRequest ## ReverseGeoCodeRequest
...@@ -1279,24 +1897,25 @@ Defines a geographic location. ...@@ -1279,24 +1897,25 @@ Defines a geographic location.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| latitude | number | No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.| | latitude<sup>7+</sup> | number | No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude | number | No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .| | longitude<sup>7+</sup> | number | No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| locale | string | No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.| | locale<sup>7+</sup> | string | No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| placeName | string | No| Landmark of the location.| | placeName<sup>7+</sup> | string | No| Landmark of the location.|
| countryCode | string | No| Country code.| | countryCode<sup>7+</sup> | string | No| Country code.|
| countryName | string | No| Country name.| | countryName<sup>7+</sup> | string | No| Country name.|
| administrativeArea | string | No| Administrative region name.| | administrativeArea<sup>7+</sup> | string | No| Administrative region name.|
| subAdministrativeArea | string | No| Sub-administrative region name.| | subAdministrativeArea<sup>7+</sup> | string | No| Sub-administrative region name.|
| locality | string | No| Locality information. | | locality<sup>7+</sup> | string | No| Locality information. |
| subLocality | string | No| Sub-locality information. | | subLocality<sup>7+</sup> | string | No| Sub-locality information. |
| roadName | string | No| Road name.| | roadName<sup>7+</sup> | string | No| Road name.|
| subRoadName | string | No| Auxiliary road information.| | subRoadName<sup>7+</sup> | string | No| Auxiliary road information.|
| premises | string | No| House information.| | premises<sup>7+</sup> | string | No| House information.|
| postalCode | string | No| Postal code.| | postalCode<sup>7+</sup> | string | No| Postal code.|
| phoneNumber | string | No| Phone number.| | phoneNumber<sup>7+</sup> | string | No| Phone number.|
| addressUrl | string | No| Website URL.| | addressUrl<sup>7+</sup> | string | No| Website URL.|
| descriptions | Array&lt;string&gt; | No| Additional description.| | descriptions<sup>7+</sup> | Array&lt;string&gt; | No| Additional description.|
| descriptionsSize | number | No| Total number of additional descriptions.| | descriptionsSize<sup>7+</sup> | number | No| Total number of additional descriptions.|
| isFromMock<sup>9+</sup> | Boolean | No | Indicates whether the geographical name information comes from the reverse geocoding simulation function. |
## LocationRequest ## LocationRequest
...@@ -1434,13 +2053,68 @@ Defines a location. ...@@ -1434,13 +2053,68 @@ Defines a location.
| Name| Type| Mandatory| Description| | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| latitude | number | Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.| | latitude<sup>7+</sup> | number | Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude | number | Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .| | longitude<sup>7+</sup> | number | Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| altitude | number | Yes| Location altitude, in meters.| | altitude<sup>7+</sup> | number | Yes| Location altitude, in meters.|
| accuracy | number | Yes| Location accuracy, in meters.| | accuracy<sup>7+</sup> | number | Yes| Location accuracy, in meters.|
| speed | number | Yes| Speed, in m/s.| | speed<sup>7+</sup> | number | Yes| Speed, in m/s.|
| timeStamp | number | Yes| Location timestamp in the UTC format.| | timeStamp<sup>7+</sup> | number | Yes| Location timestamp in the UTC format.|
| direction | number | Yes| Direction information.| | direction<sup>7+</sup> | number | Yes| Direction information.|
| timeSinceBoot | number | Yes| Location timestamp since boot.| | timeSinceBoot<sup>7+</sup> | number | Yes| Location timestamp since boot.|
| additions | Array&lt;string&gt; | No| Additional information.| | additions<sup>7+</sup> | Array&lt;string&gt; | No| Additional information.|
| additionSize | number | No| Number of additional descriptions.| | additionSize<sup>7+</sup> | number | No| Number of additional descriptions.|
| isFromMock<sup>9+</sup> | Boolean | No | Indicates whether the location information comes from the location simulation function. |
## ReverseGeocodingMockInfo<sup>9+</sup>
The configuration information of the reverse geocoding simulation function includes a location information and a place name information.
**System capability**:SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| location | ReverseGeoCodeRequest | Yes | Indicates longitude and latitude information. |
| geoAddress | GeoAddress | Yes | Represents a geographic location. |
## LocationMockConfig<sup>9+</sup>
The configuration parameters of the location simulation function include the time interval of the simulation position report and the array of simulation locations.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| timeInterval | number | Yes | Indicates the time interval of analog location reporting, in seconds. |
| locations | Array&lt;Location&gt; | Yes | Represents an array of mocked locations. |
## CountryCode<sup>9+</sup>
The country code information structure contains the country code string and the source information of the country code.
**System capability**: SystemCapability.Location.Location.Core
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| country | string | Yes | Represents the country code string. |
| type | CountryCodeType | Yes | Indicates the source of country code information. |
## CountryCodeType<sup>9+</sup>
Country code source type.
**System capability**: SystemCapability.Location.Location.Core
| Name| Default Value| Description|
| -------- | -------- | -------- |
| COUNTRY_CODE_FROM_LOCALE | 1 | The country code obtained from the language configuration information of the globalization module. |
| COUNTRY_CODE_FROM_SIM | 2 | The country code obtained from the SIM card. |
| COUNTRY_CODE_FROM_LOCATION | 3 | Based on the user's location information, the country code is queried through reverse geocoding. |
| COUNTRY_CODE_FROM_NETWORK | 4 | The country code obtained from the cellular network registration information. |
\ No newline at end of file
...@@ -8,8 +8,7 @@ ...@@ -8,8 +8,7 @@
## 导入模块 ## 导入模块
```js
```
import geolocation from '@ohos.geolocation'; import geolocation from '@ohos.geolocation';
``` ```
...@@ -23,7 +22,8 @@ on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Locat ...@@ -23,7 +22,8 @@ on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Locat
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“locationChange”,表示位置变化。 | | type | string | 是 | 设置事件类型。type为“locationChange”,表示位置变化。 |
...@@ -31,9 +31,9 @@ on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Locat ...@@ -31,9 +31,9 @@ on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Locat
| callback | Callback&lt;[Location](#location)&gt; | 是 | 接收位置变化状态变化监听。 | | callback | Callback&lt;[Location](#location)&gt; | 是 | 接收位置变化状态变化监听。 |
- 示例: **示例**
``` ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => { var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location)); console.log('locationChanger: data: ' + JSON.stringify(location));
...@@ -52,16 +52,17 @@ off(type: 'locationChange', callback?: Callback&lt;Location&gt;) : void ...@@ -52,16 +52,17 @@ off(type: 'locationChange', callback?: Callback&lt;Location&gt;) : void
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“locationChange”,表示位置变化。 | | type | string | 是 | 设置事件类型。type为“locationChange”,表示位置变化。 |
| callback | Callback&lt;[Location](#location)&gt; | 否 | 接收位置变化状态变化监听。 | | callback | Callback&lt;[Location](#location)&gt; | 否 | 接收位置变化状态变化监听。 |
- 示例: **示例**
``` ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => { var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location)); console.log('locationChanger: data: ' + JSON.stringify(location));
...@@ -81,18 +82,19 @@ on(type: 'locationServiceState', callback: Callback&lt;boolean&gt;) : void ...@@ -81,18 +82,19 @@ on(type: 'locationServiceState', callback: Callback&lt;boolean&gt;) : void
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“locationServiceState”,表示位置服务状态。 | | type | string | 是 | 设置事件类型。type为“locationServiceState”,表示位置服务状态。 |
| callback | Callback&lt;boolean&gt; | 是 | 接收位置服务状态变化监听。 | | callback | Callback&lt;boolean&gt; | 是 | 接收位置服务状态变化监听。 |
- 示例: **示例**
``` ```js
var locationServiceState = (state) => { var locationServiceState = (state) => {
console.log('locationServiceState: ' + state); console.log('locationServiceState: ' + JSON.stringify(state));
} }
geolocation.on('locationServiceState', locationServiceState); geolocation.on('locationServiceState', locationServiceState);
``` ```
...@@ -108,18 +110,19 @@ off(type: 'locationServiceState', callback?: Callback&lt;boolean&gt;) : void; ...@@ -108,18 +110,19 @@ off(type: 'locationServiceState', callback?: Callback&lt;boolean&gt;) : void;
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“locationServiceState”,表示位置服务状态。 | | type | string | 是 | 设置事件类型。type为“locationServiceState”,表示位置服务状态。 |
| callback | Callback&lt;boolean&gt; | 否 | 接收位置服务状态变化监听。 | | callback | Callback&lt;boolean&gt; | 否 | 接收位置服务状态变化监听。 |
- 示例: **示例**
``` ```js
var locationServiceState = (state) => { var locationServiceState = (state) => {
console.log('locationServiceState: state: ' + state); console.log('locationServiceState: state: ' + JSON.stringify(state));
} }
geolocation.on('locationServiceState', locationServiceState); geolocation.on('locationServiceState', locationServiceState);
geolocation.off('locationServiceState', locationServiceState); geolocation.off('locationServiceState', locationServiceState);
...@@ -136,7 +139,8 @@ on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, ca ...@@ -136,7 +139,8 @@ on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, ca
**系统能力**:SystemCapability.Location.Location.Gnss **系统能力**:SystemCapability.Location.Location.Gnss
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“cachedGnssLocationsReporting”,表示GNSS缓存定位结果上报。 | | type | string | 是 | 设置事件类型。type为“cachedGnssLocationsReporting”,表示GNSS缓存定位结果上报。 |
...@@ -144,11 +148,11 @@ on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, ca ...@@ -144,11 +148,11 @@ on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, ca
| callback | Callback&lt;boolean&gt; | 是 | 接收GNSS缓存位置上报。 | | callback | Callback&lt;boolean&gt; | 是 | 接收GNSS缓存位置上报。 |
- 示例: **示例**
``` ```js
var cachedLocationsCb = (locations) => { var cachedLocationsCb = (locations) => {
console.log('cachedGnssLocationsReporting: locations: ' + locations); console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
} }
var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb); geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
...@@ -165,18 +169,19 @@ off(type: 'cachedGnssLocationsReporting', callback?: Callback&lt;Array&lt;Locati ...@@ -165,18 +169,19 @@ off(type: 'cachedGnssLocationsReporting', callback?: Callback&lt;Array&lt;Locati
**系统能力**:SystemCapability.Location.Location.Gnss **系统能力**:SystemCapability.Location.Location.Gnss
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“cachedGnssLocationsReporting”,表示GNSS缓存定位结果上报。 | | type | string | 是 | 设置事件类型。type为“cachedGnssLocationsReporting”,表示GNSS缓存定位结果上报。 |
| callback | Callback&lt;boolean&gt; | 否 | 接收GNSS缓存位置上报。 | | callback | Callback&lt;boolean&gt; | 否 | 接收GNSS缓存位置上报。 |
- 示例: **示例**
``` ```js
var cachedLocationsCb = (locations) => { var cachedLocationsCb = (locations) => {
console.log('cachedGnssLocationsReporting: locations: ' + locations); console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
} }
var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true}; var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb); geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
...@@ -194,18 +199,19 @@ on(type: 'gnssStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;) : vo ...@@ -194,18 +199,19 @@ on(type: 'gnssStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;) : vo
**系统能力**:SystemCapability.Location.Location.Gnss **系统能力**:SystemCapability.Location.Location.Gnss
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“gnssStatusChange”,表示订阅GNSS卫星状态信息上报。 | | type | string | 是 | 设置事件类型。type为“gnssStatusChange”,表示订阅GNSS卫星状态信息上报。 |
| callback | Callback&lt;SatelliteStatusInfo&gt; | 是 | 接收GNSS卫星状态信息上报。 | | callback | Callback&lt;SatelliteStatusInfo&gt; | 是 | 接收GNSS卫星状态信息上报。 |
- 示例: **示例**
``` ```js
var gnssStatusCb = (satelliteStatusInfo) => { var gnssStatusCb = (satelliteStatusInfo) => {
console.log('gnssStatusChange: ' + satelliteStatusInfo); console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
} }
geolocation.on('gnssStatusChange', gnssStatusCb); geolocation.on('gnssStatusChange', gnssStatusCb);
``` ```
...@@ -221,17 +227,18 @@ off(type: 'gnssStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;) : ...@@ -221,17 +227,18 @@ off(type: 'gnssStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;) :
**系统能力**:SystemCapability.Location.Location.Gnss **系统能力**:SystemCapability.Location.Location.Gnss
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“gnssStatusChange”,表示订阅GNSS卫星状态信息上报。 | | type | string | 是 | 设置事件类型。type为“gnssStatusChange”,表示订阅GNSS卫星状态信息上报。 |
| callback | Callback&lt;SatelliteStatusInfo&gt; | 否 | 接收GNSS卫星状态信息上报。 | | callback | Callback&lt;SatelliteStatusInfo&gt; | 否 | 接收GNSS卫星状态信息上报。 |
- 示例: **示例**
``` ```js
var gnssStatusCb = (satelliteStatusInfo) => { var gnssStatusCb = (satelliteStatusInfo) => {
console.log('gnssStatusChange: ' + satelliteStatusInfo); console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
} }
geolocation.on('gnssStatusChange', gnssStatusCb); geolocation.on('gnssStatusChange', gnssStatusCb);
geolocation.off('gnssStatusChange', gnssStatusCb); geolocation.off('gnssStatusChange', gnssStatusCb);
...@@ -248,18 +255,19 @@ on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;) : void; ...@@ -248,18 +255,19 @@ on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;) : void;
**系统能力**:SystemCapability.Location.Location.Gnss **系统能力**:SystemCapability.Location.Location.Gnss
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“nmeaMessageChange”,表示订阅GNSS&nbsp;NMEA信息上报。 | | type | string | 是 | 设置事件类型。type为“nmeaMessageChange”,表示订阅GNSS&nbsp;NMEA信息上报。 |
| callback | Callback&lt;string&gt; | 是 | 接收GNSS&nbsp;NMEA信息上报。 | | callback | Callback&lt;string&gt; | 是 | 接收GNSS&nbsp;NMEA信息上报。 |
- 示例: **示例**
``` ```js
var nmeaCb = (str) => { var nmeaCb = (str) => {
console.log('nmeaMessageChange: ' + str); console.log('nmeaMessageChange: ' + JSON.stringify(str));
} }
geolocation.on('nmeaMessageChange', nmeaCb ); geolocation.on('nmeaMessageChange', nmeaCb );
``` ```
...@@ -275,18 +283,19 @@ off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;) : void; ...@@ -275,18 +283,19 @@ off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;) : void;
**系统能力**:SystemCapability.Location.Location.Gnss **系统能力**:SystemCapability.Location.Location.Gnss
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“nmeaMessageChange”,表示订阅GNSS&nbsp;NMEA信息上报。 | | type | string | 是 | 设置事件类型。type为“nmeaMessageChange”,表示订阅GNSS&nbsp;NMEA信息上报。 |
| callback | Callback&lt;string&gt; | 否 | 接收GNSS&nbsp;NMEA信息上报。 | | callback | Callback&lt;string&gt; | 否 | 接收GNSS&nbsp;NMEA信息上报。 |
- 示例: **示例**
``` ```js
var nmeaCb = (str) => { var nmeaCb = (str) => {
console.log('nmeaMessageChange: ' + str); console.log('nmeaMessageChange: ' + JSON.stringify(str));
} }
geolocation.on('nmeaMessageChange', nmeaCb); geolocation.on('nmeaMessageChange', nmeaCb);
geolocation.off('nmeaMessageChange', nmeaCb); geolocation.off('nmeaMessageChange', nmeaCb);
...@@ -303,7 +312,8 @@ on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void; ...@@ -303,7 +312,8 @@ on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void;
**系统能力**:SystemCapability.Location.Location.Geofence **系统能力**:SystemCapability.Location.Location.Geofence
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“fenceStatusChange”,表示订阅围栏事件上报。 | | type | string | 是 | 设置事件类型。type为“fenceStatusChange”,表示订阅围栏事件上报。 |
...@@ -311,52 +321,29 @@ on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void; ...@@ -311,52 +321,29 @@ on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void;
| want | WantAgent | 是 | 用于接收地理围栏事件上报(进出围栏)。 | | want | WantAgent | 是 | 用于接收地理围栏事件上报(进出围栏)。 |
- 示例: **示例**
``` ```js
import WantAgent from '@ohos.wantAgent'; import geolocation from '@ohos.geolocation';
import { OperationType, WantAgentFlags } from '@ohos.wantagent'; import wantAgent from '@ohos.wantAgent';
//wantAgent对象
var wantAgent; let wantAgentInfo = {
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [ wants: [
{ {
deviceId: "deviceId", bundleName: "com.example.myapplication",
bundleName: "com.neu.setResultOnAbilityResultTest1", abilityName: "com.example.myapplication.MainAbility"
abilityName: "com.example.test.MainAbility",
action: "action1", action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} };
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}}; var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
geolocation.on('fenceStatusChange', requestInfo, wantAgent); geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
});
``` ```
...@@ -370,60 +357,91 @@ off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void ...@@ -370,60 +357,91 @@ off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void
**系统能力**:SystemCapability.Location.Location.Geofence **系统能力**:SystemCapability.Location.Location.Geofence
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“fenceStatusChange”,表示订阅围栏事件上报。 | | type | string | 是 | 设置事件类型。type为“fenceStatusChange”,表示订阅围栏事件上报。 |
| request | GeofenceRequest | 是 | 围栏的配置参数。 | | request | GeofenceRequest | 是 | 围栏的配置参数。 |
| want | WantAgent | 是 | 用于接收地理围栏事件上报(进出围栏)。 | | want | WantAgent | 是 | 用于接收地理围栏事件上报(进出围栏)。 |
- 示例: **示例**
``` ```js
import WantAgent from '@ohos.wantAgent'; import geolocation from '@ohos.geolocation';
import { OperationType, WantAgentFlags } from '@ohos.wantagent'; import wantAgent from '@ohos.wantAgent';
//wantAgent对象
var wantAgent; let wantAgentInfo = {
//getWantAgent回调
function getWantAgentCallback(err, data) {
console.info("==========================>getWantAgentCallback=======================>");
if (err.code == 0) {
wantAgent = data;
} else {
console.info('----getWantAgent failed!----');
}
}
//WantAgentInfo对象
var wantAgentInfo = {
wants: [ wants: [
{ {
deviceId: "deviceId", bundleName: "com.example.myapplication",
bundleName: "com.neu.setResultOnAbilityResultTest1", abilityName: "com.example.myapplication.MainAbility"
abilityName: "com.example.test.MainAbility",
action: "action1", action: "action1",
entities: ["entity1"],
type: "MIMETYPE",
uri: "key={true,true,false}",
parameters:
{
mykey0: 2222,
mykey1: [1, 2, 3],
mykey2: "[1, 2, 3]",
mykey3: "ssssssssssssssssssssssssss",
mykey4: [false, true, false],
mykey5: ["qqqqq", "wwwwww", "aaaaaaaaaaaaaaaaa"],
mykey6: true,
}
} }
], ],
operationType: OperationType.START_ABILITIES, operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0, requestCode: 0,
wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG] wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
} };
WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}}; var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
geolocation.on('fenceStatusChange', requestInfo, wantAgent); geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
geolocation.off('fenceStatusChange', requestInfo, wantAgent); geolocation.off('fenceStatusChange', requestInfo, wantAgentObj);
});
```
## geolocation.on('countryCodeChange')<sup>9+</sup>
on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;) : void;
订阅国家码信息上报事件。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示订阅国家码信息上报。 |
| callback | Callback&lt;CountryCode&gt; | 是 | 接收国家码信息上报。 |
**示例**
```js
var callback = (code) => {
console.log('countryCodeChange: ' + JSON.stringify(code));
}
geolocation.on('countryCodeChange', callback);
```
## geolocation.off('countryCodeChange')<sup>9+</sup>
off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;) : void;
取消订阅国家码上报事件。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示取消订阅国家码信息上报。 |
| callback | Callback&lt;CountryCode&gt; | 是 | 接收国家码信息上报。 |
**示例**
```js
var callback = (code) => {
console.log('countryCodeChange: ' + JSON.stringify(code));
}
geolocation.on('countryCodeChange', callback);
geolocation.off('countryCodeChange', callback);
``` ```
...@@ -438,18 +456,24 @@ getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;L ...@@ -438,18 +456,24 @@ getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;L
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [CurrentLocationRequest](#currentlocationrequest) | 否 | 设置位置请求参数。 | | request | [CurrentLocationRequest](#currentlocationrequest) | 否 | 设置位置请求参数。 |
| callback | AsyncCallback&lt;[Location](#location)&gt; | 是 | 用来接收位置信息的回调。 | | callback | AsyncCallback&lt;[Location](#location)&gt; | 是 | 用来接收位置信息的回调。 |
- 示例: **示例**
``` ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0}; var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
var locationChange = (err, location) => { var locationChange = (err, location) => {
console.log('locationChanger: ' + err + 'data: ' + location); if (err) {
console.log('locationChanger: err=' + JSON.stringify(err));
}
if (location) {
console.log('locationChanger: location=' + JSON.stringify(location));
}
}; };
geolocation.getCurrentLocation(requestInfo, locationChange); geolocation.getCurrentLocation(requestInfo, locationChange);
geolocation.getCurrentLocation(locationChange); geolocation.getCurrentLocation(locationChange);
...@@ -467,22 +491,24 @@ getCurrentLocation(request?: CurrentLocationRequest) : Promise&lt;Location&gt; ...@@ -467,22 +491,24 @@ getCurrentLocation(request?: CurrentLocationRequest) : Promise&lt;Location&gt;
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [CurrentLocationRequest](#currentlocationrequest) | 否 | 设置位置请求参数。 | | request | [CurrentLocationRequest](#currentlocationrequest) | 否 | 设置位置请求参数。 |
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;[Location](#location)&gt; | 返回位置信息。 | | Promise&lt;[Location](#location)&gt; | 返回位置信息。 |
- 示例: **示例**
``` ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0}; var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
locationEventListener.getCurrentLocation(requestInfo).then((result) => { geolocation.getCurrentLocation(requestInfo).then((result) => {
console.log('current location: ' + JSON.stringify(result)); console.log('current location: ' + JSON.stringify(result));
}); });
``` ```
...@@ -498,17 +524,23 @@ getLastLocation(callback: AsyncCallback&lt;Location&gt;) : void ...@@ -498,17 +524,23 @@ getLastLocation(callback: AsyncCallback&lt;Location&gt;) : void
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Location](#location)&gt; | 是 | 用来接收上次位置的回调。 | | callback | AsyncCallback&lt;[Location](#location)&gt; | 是 | 用来接收上次位置的回调。 |
- 示例: **示例**
``` ```js
geolocation.getLastLocation((err, data) => { geolocation.getLastLocation((err, data) => {
console.log('getLastLocation: ' + err + " data: " + JSON.stringify(data)); if (err) {
console.log('getLastLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('getLastLocation: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -523,15 +555,16 @@ getLastLocation() : Promise&lt;Location&gt; ...@@ -523,15 +555,16 @@ getLastLocation() : Promise&lt;Location&gt;
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;[Location](#location)&gt; | 返回上次位置信息。 | | Promise&lt;[Location](#location)&gt; | 返回上次位置信息。 |
- 示例: **示例**
``` ```js
geolocation.getLastLocation().then((result) => { geolocation.getLastLocation().then((result) => {
console.log('getLastLocation: result: ' + JSON.stringify(result)); console.log('getLastLocation: result: ' + JSON.stringify(result));
}); });
...@@ -549,17 +582,22 @@ isLocationEnabled(callback: AsyncCallback&lt;boolean&gt;) : void ...@@ -549,17 +582,22 @@ isLocationEnabled(callback: AsyncCallback&lt;boolean&gt;) : void
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收位置服务状态的回调。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收位置服务状态的回调。 |
**示例**
- 示例: ```js
```
geolocation.isLocationEnabled((err, data) => { geolocation.isLocationEnabled((err, data) => {
console.log('isLocationEnabled: ' + err + " data: " + data); if (err) {
console.log('isLocationEnabled: err=' + JSON.stringify(err));
}
if (data) {
console.log('isLocationEnabled: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -574,16 +612,17 @@ isLocationEnabled() : Promise&lt;boolean&gt; ...@@ -574,16 +612,17 @@ isLocationEnabled() : Promise&lt;boolean&gt;
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | 返回位置服务是否可用的状态。 | | Promise&lt;boolean&gt; | 返回位置服务是否可用的状态。 |
- 示例: **示例**
``` ```js
geolocation.isLocationEnabled().then((result) => { geolocation.isLocationEnabled().then((result) => {
console.log('promise, isLocationEnabled: ' + result); console.log('promise, isLocationEnabled: ' + JSON.stringify(result));
}); });
``` ```
...@@ -599,17 +638,22 @@ requestEnableLocation(callback: AsyncCallback&lt;boolean&gt;) : void ...@@ -599,17 +638,22 @@ requestEnableLocation(callback: AsyncCallback&lt;boolean&gt;) : void
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收位置服务状态的回调。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收位置服务状态的回调。 |
**示例**
- 示例: ```js
```
geolocation.requestEnableLocation((err, data) => { geolocation.requestEnableLocation((err, data) => {
console.log('requestEnableLocation: ' + err + " data: " + data); if (err) {
console.log('requestEnableLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('requestEnableLocation: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -624,17 +668,17 @@ requestEnableLocation() : Promise&lt;boolean&gt; ...@@ -624,17 +668,17 @@ requestEnableLocation() : Promise&lt;boolean&gt;
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | 返回位置服务是否可用。 | | Promise&lt;boolean&gt; | 返回位置服务是否可用。 |
**示例**
- 示例: ```js
```
geolocation.requestEnableLocation().then((result) => { geolocation.requestEnableLocation().then((result) => {
console.log('promise, requestEnableLocation: ' + result); console.log('promise, requestEnableLocation: ' + JSON.stringify(result));
}); });
``` ```
...@@ -647,21 +691,26 @@ enableLocation(callback: AsyncCallback&lt;boolean&gt;) : void; ...@@ -647,21 +691,26 @@ enableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
**系统API**:此接口为系统接口,三方应用不支持调用。 **系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.LOCATION **需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收位置服务状态的回调。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收位置服务状态的回调。 |
**示例**
- 示例: ```js
```
geolocation.enableLocation((err, data) => { geolocation.enableLocation((err, data) => {
console.log('enableLocation: ' + err + " data: " + data); if (err) {
console.log('enableLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('enableLocation: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -674,21 +723,21 @@ enableLocation() : Promise&lt;boolean&gt; ...@@ -674,21 +723,21 @@ enableLocation() : Promise&lt;boolean&gt;
**系统API**:此接口为系统接口,三方应用不支持调用。 **系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.LOCATION **需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | 返回位置服务是否可用。 | | Promise&lt;boolean&gt; | 返回位置服务是否可用。 |
**示例**
- 示例: ```js
```
geolocation.enableLocation().then((result) => { geolocation.enableLocation().then((result) => {
console.log('promise, enableLocation: ' + result); console.log('promise, enableLocation: ' + JSON.stringify(result));
}); });
``` ```
...@@ -700,21 +749,26 @@ disableLocation(callback: AsyncCallback&lt;boolean&gt;) : void; ...@@ -700,21 +749,26 @@ disableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
**系统API**:此接口为系统接口,三方应用不支持调用。 **系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.LOCATION **需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收位置服务状态的回调。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收位置服务状态的回调。 |
**示例**
- 示例: ```js
```
geolocation.disableLocation((err, data) => { geolocation.disableLocation((err, data) => {
console.log('disableLocation: ' + err + " data: " + data); if (err) {
console.log('disableLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('disableLocation: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -727,21 +781,21 @@ disableLocation() : Promise&lt;boolean&gt; ...@@ -727,21 +781,21 @@ disableLocation() : Promise&lt;boolean&gt;
**系统API**:此接口为系统接口,三方应用不支持调用。 **系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.LOCATION **需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | 返回位置服务是否可用。 | | Promise&lt;boolean&gt; | 返回位置服务是否可用。 |
**示例**
- 示例: ```js
```
geolocation.disableLocation().then((result) => { geolocation.disableLocation().then((result) => {
console.log('promise, disableLocation: ' + result); console.log('promise, disableLocation: ' + JSON.stringify(result));
}); });
``` ```
...@@ -755,17 +809,22 @@ isGeoServiceAvailable(callback: AsyncCallback&lt;boolean&gt;) : void ...@@ -755,17 +809,22 @@ isGeoServiceAvailable(callback: AsyncCallback&lt;boolean&gt;) : void
**系统能力**:SystemCapability.Location.Location.Geocoder **系统能力**:SystemCapability.Location.Location.Geocoder
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收地理编码服务状态的回调。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收地理编码服务状态的回调。 |
**示例**
- 示例: ```js
```
geolocation.isGeoServiceAvailable((err, data) => { geolocation.isGeoServiceAvailable((err, data) => {
console.log('isGeoServiceAvailable: ' + err + " data: " + data); if (err) {
console.log('isGeoServiceAvailable: err=' + JSON.stringify(err));
}
if (data) {
console.log('isGeoServiceAvailable: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -780,22 +839,21 @@ isGeoServiceAvailable() : Promise&lt;boolean&gt; ...@@ -780,22 +839,21 @@ isGeoServiceAvailable() : Promise&lt;boolean&gt;
**系统能力**:SystemCapability.Location.Location.Geocoder **系统能力**:SystemCapability.Location.Location.Geocoder
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | 返回地理编码服务是否可用的状态。 | | Promise&lt;boolean&gt; | 返回地理编码服务是否可用的状态。 |
**示例**
- 示例: ```js
```
geolocation.isGeoServiceAvailable().then((result) => { geolocation.isGeoServiceAvailable().then((result) => {
console.log('promise, isGeoServiceAvailable: ' + result); console.log('promise, isGeoServiceAvailable: ' + JSON.stringify(result));
}); });
``` ```
## geolocation.getAddressesFromLocation ## geolocation.getAddressesFromLocation
getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;) : void getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;) : void
...@@ -806,18 +864,24 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback ...@@ -806,18 +864,24 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback
**系统能力**:SystemCapability.Location.Location.Geocoder **系统能力**:SystemCapability.Location.Location.Geocoder
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 设置逆地理编码请求的相关参数。 | | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 设置逆地理编码请求的相关参数。 |
| callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 是 | 设置接收逆地理编码请求的回调参数。 | | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 是 | 设置接收逆地理编码请求的回调参数。 |
- 示例: **示例**
``` ```js
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
console.log('getAddressesFromLocation: ' + err + " data: " + JSON.stringify(data)); if (err) {
console.log('getAddressesFromLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('getAddressesFromLocation: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -832,19 +896,21 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest) : Promise&lt;Array&lt;G ...@@ -832,19 +896,21 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest) : Promise&lt;Array&lt;G
**系统能力**:SystemCapability.Location.Location.Geocoder **系统能力**:SystemCapability.Location.Location.Geocoder
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 设置逆地理编码请求的相关参数。 | | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 设置逆地理编码请求的相关参数。 |
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 返回地理描述信息。 | | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 返回地理描述信息。 |
- 示例: **示例**
``` ```js
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; var 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));
...@@ -862,19 +928,24 @@ getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt ...@@ -862,19 +928,24 @@ getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt
**系统能力**:SystemCapability.Location.Location.Geocoder **系统能力**:SystemCapability.Location.Location.Geocoder
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [GeoCodeRequest](#geocoderequest) | 是 | 设置地理编码请求的相关参数。 | | request | [GeoCodeRequest](#geocoderequest) | 是 | 设置地理编码请求的相关参数。 |
| callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 是 | 设置接收地理编码请求的回调参数。 | | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 是 | 设置接收地理编码请求的回调参数。 |
**示例**
- 示例: ```js
```
var geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1}; var geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => { geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => {
console.log('getAddressesFromLocationName: ' + err + " data: " + JSON.stringify(data)); if (err) {
console.log('getAddressesFromLocationName: err=' + JSON.stringify(err));
}
if (data) {
console.log('getAddressesFromLocationName: data=' + JSON.stringify(data));
}
}); });
``` ```
...@@ -889,19 +960,21 @@ getAddressesFromLocationName(request: GeoCodeRequest) : Promise&lt;Array&lt;GeoA ...@@ -889,19 +960,21 @@ getAddressesFromLocationName(request: GeoCodeRequest) : Promise&lt;Array&lt;GeoA
**系统能力**:SystemCapability.Location.Location.Geocoder **系统能力**:SystemCapability.Location.Location.Geocoder
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| request | [GeoCodeRequest](#geocoderequest) | 是 | 设置地理编码请求的相关参数。 | | request | [GeoCodeRequest](#geocoderequest) | 是 | 设置地理编码请求的相关参数。 |
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 设置接收地理编码请求的回调参数。 | | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | 设置接收地理编码请求的回调参数。 |
- 示例: **示例**
``` ```js
var geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1}; var 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));
...@@ -909,7 +982,6 @@ getAddressesFromLocationName(request: GeoCodeRequest) : Promise&lt;Array&lt;GeoA ...@@ -909,7 +982,6 @@ getAddressesFromLocationName(request: GeoCodeRequest) : Promise&lt;Array&lt;GeoA
``` ```
## geolocation.getCachedGnssLocationsSize<sup>8+</sup> ## geolocation.getCachedGnssLocationsSize<sup>8+</sup>
getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;) : void; getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;) : void;
...@@ -920,16 +992,22 @@ getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;) : void; ...@@ -920,16 +992,22 @@ getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;) : void;
**系统能力**:SystemCapability.Location.Location.Gnss **系统能力**:SystemCapability.Location.Location.Gnss
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;number&gt; | 是 | 用来接收GNSS芯片缓存位置个数的回调。 | | callback | AsyncCallback&lt;number&gt; | 是 | 用来接收GNSS芯片缓存位置个数的回调。 |
- 示例: **示例**
``` ```js
geolocation.getCachedGnssLocationsSize((err, size) => { geolocation.getCachedGnssLocationsSize((err, size) => {
console.log('getCachedGnssLocationsSize: err:' + err + " size: " + size); if (err) {
console.log('getCachedGnssLocationsSize: err=' + JSON.stringify(err));
}
if (size) {
console.log('getCachedGnssLocationsSize: size=' + JSON.stringify(size));
}
}); });
``` ```
...@@ -944,16 +1022,17 @@ getCachedGnssLocationsSize() : Promise&lt;number&gt;; ...@@ -944,16 +1022,17 @@ getCachedGnssLocationsSize() : Promise&lt;number&gt;;
**系统能力**:SystemCapability.Location.Location.Gnss **系统能力**:SystemCapability.Location.Location.Gnss
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;number&gt; | 返回GNSS缓存位置的个数。 | | Promise&lt;number&gt; | 返回GNSS缓存位置的个数。 |
- 示例: **示例**
``` ```js
geolocation.getCachedGnssLocationsSize().then((result) => { geolocation.getCachedGnssLocationsSize().then((result) => {
console.log('promise, getCachedGnssLocationsSize: ' + result); console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
}); });
``` ```
...@@ -968,16 +1047,22 @@ flushCachedGnssLocations(callback: AsyncCallback&lt;boolean&gt;) : void; ...@@ -968,16 +1047,22 @@ flushCachedGnssLocations(callback: AsyncCallback&lt;boolean&gt;) : void;
**系统能力**:SystemCapability.Location.Location.Gnss **系统能力**:SystemCapability.Location.Location.Gnss
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收清空GNSS芯片缓存位置操作的结果。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收清空GNSS芯片缓存位置操作的结果。 |
- 示例: **示例**
``` ```js
geolocation.flushCachedGnssLocations((err, result) => { geolocation.flushCachedGnssLocations((err, result) => {
console.log('flushCachedGnssLocations: err:' + err + " result: " + result); if (err) {
console.log('flushCachedGnssLocations: err=' + JSON.stringify(err));
}
if (result) {
console.log('flushCachedGnssLocations: result=' + JSON.stringify(result));
}
}); });
``` ```
...@@ -992,16 +1077,17 @@ flushCachedGnssLocations() : Promise&lt;boolean&gt;; ...@@ -992,16 +1077,17 @@ flushCachedGnssLocations() : Promise&lt;boolean&gt;;
**系统能力**:SystemCapability.Location.Location.Gnss **系统能力**:SystemCapability.Location.Location.Gnss
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | 清空所有GNSS缓存位置是否成功。 | | Promise&lt;boolean&gt; | 清空所有GNSS缓存位置是否成功。 |
- 示例: **示例**
``` ```js
geolocation.flushCachedGnssLocations().then((result) => { geolocation.flushCachedGnssLocations().then((result) => {
console.log('promise, flushCachedGnssLocations: ' + result); console.log('promise, flushCachedGnssLocations: ' + JSON.stringify(result));
}); });
``` ```
...@@ -1016,18 +1102,24 @@ sendCommand(command: LocationCommand, callback: AsyncCallback&lt;boolean&gt;) : ...@@ -1016,18 +1102,24 @@ sendCommand(command: LocationCommand, callback: AsyncCallback&lt;boolean&gt;) :
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| command | LocationCommand | 是 | 指定目标场景,和将要发送的命令(字符串)。 | | command | LocationCommand | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收命令发送的结果。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收命令发送的结果。 |
- 示例: **示例**
``` ```js
var requestInfo = {'scenario': 0x301, 'command': "command_1"}; var requestInfo = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo, (err, result) => { geolocation.sendCommand(requestInfo, (err, result) => {
console.log('sendCommand: err:' + err + " result: " + result); if (err) {
console.log('sendCommand: err=' + JSON.stringify(err));
}
if (result) {
console.log('sendCommand: result=' + JSON.stringify(result));
}
}); });
``` ```
...@@ -1042,22 +1134,24 @@ sendCommand(command: LocationCommand) : Promise&lt;boolean&gt;; ...@@ -1042,22 +1134,24 @@ sendCommand(command: LocationCommand) : Promise&lt;boolean&gt;;
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| command | LocationCommand | 是 | 指定目标场景,和将要发送的命令(字符串)。 | | command | LocationCommand | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | 表示命令发送成功或失败。 | | Promise&lt;boolean&gt; | 表示命令发送成功或失败。 |
- 示例: **示例**
``` ```js
var requestInfo = {'scenario': 0x301, 'command': "command_1"}; var requestInfo = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo).then((result) => { geolocation.sendCommand(requestInfo).then((result) => {
console.log('promise, sendCommand: ' + result); console.log('promise, sendCommand: ' + JSON.stringify(result));
}); });
``` ```
...@@ -1074,17 +1168,23 @@ isLocationPrivacyConfirmed(type : LocationPrivacyType, callback: AsyncCallback&l ...@@ -1074,17 +1168,23 @@ isLocationPrivacyConfirmed(type : LocationPrivacyType, callback: AsyncCallback&l
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 | | type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 表示用户是否同意定位服务隐私申明。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 表示用户是否同意定位服务隐私申明。 |
- 示例: **示例**
``` ```js
geolocation.isLocationPrivacyConfirmed(1, (err, result) => { geolocation.isLocationPrivacyConfirmed(1, (err, result) => {
console.log('isLocationPrivacyConfirmed: err:' + err + " result: " + result); if (err) {
console.log('isLocationPrivacyConfirmed: err=' + JSON.stringify(err));
}
if (result) {
console.log('isLocationPrivacyConfirmed: result=' + JSON.stringify(result));
}
}); });
``` ```
...@@ -1101,21 +1201,23 @@ isLocationPrivacyConfirmed(type : LocationPrivacyType,) : Promise&lt;boolean&gt; ...@@ -1101,21 +1201,23 @@ isLocationPrivacyConfirmed(type : LocationPrivacyType,) : Promise&lt;boolean&gt;
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 | | type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | 表示用户是否同意定位服务隐私申明。 | | Promise&lt;boolean&gt; | 表示用户是否同意定位服务隐私申明。 |
- 示例: **示例**
``` ```js
geolocation.isLocationPrivacyConfirmed(1).then((result) => { geolocation.isLocationPrivacyConfirmed(1).then((result) => {
console.log('promise, isLocationPrivacyConfirmed: ' + result); console.log('promise, isLocationPrivacyConfirmed: ' + JSON.stringify(result));
}); });
``` ```
...@@ -1132,18 +1234,24 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed: boolean ...@@ -1132,18 +1234,24 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed: boolean
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 | | type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 | | isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 表示操作是否成功。 | | callback | AsyncCallback&lt;boolean&gt; | 是 | 表示操作是否成功。 |
- 示例: **示例**
``` ```js
geolocation.setLocationPrivacyConfirmStatus(1, true, (err, result) => { geolocation.setLocationPrivacyConfirmStatus(1, true, (err, result) => {
console.log('isLocationPrivacyConfirmed: err:' + err + " result: " + result); if (err) {
console.log('setLocationPrivacyConfirmStatus: err=' + JSON.stringify(err));
}
if (result) {
console.log('setLocationPrivacyConfirmStatus: result=' + JSON.stringify(result));
}
}); });
``` ```
...@@ -1160,26 +1268,534 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolea ...@@ -1160,26 +1268,534 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolea
**系统能力**:SystemCapability.Location.Location.Core **系统能力**:SystemCapability.Location.Location.Core
- 参数: **参数**
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 | | type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 | | isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 |
- 返回值: **返回值**
| 参数名 | 说明 | | 参数名 | 说明 |
| -------- | -------- | | -------- | -------- |
| Promise&lt;boolean&gt; | 表示操作是否成功。 | | Promise&lt;boolean&gt; | 表示操作是否成功。 |
- 示例: **示例**
``` ```js
geolocation.setLocationPrivacyConfirmStatus(1, true).then((result) => { geolocation.setLocationPrivacyConfirmStatus(1, true).then((result) => {
console.log('promise, setLocationPrivacyConfirmStatus: ' + result); console.log('promise, setLocationPrivacyConfirmStatus: ' + JSON.stringify(result));
});
```
## geolocation.getCountryCode<sup>9+</sup>
getCountryCode(callback: AsyncCallback&lt;CountryCode&gt;) : void;
查询当前的国家码。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;CountryCode&gt; | 是 | 用来接收国家码。 |
**示例**
```js
geolocation.getCountryCode((err, result) => {
if (err) {
console.log('getCountryCode: err=' + JSON.stringify(err));
}
if (result) {
console.log('getCountryCode: result=' + JSON.stringify(result));
}
});
```
## geolocation.getCountryCode<sup>9+</sup>
getCountryCode() : Promise&lt;CountryCode&gt;;
查询当前的国家码。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;CountryCode&gt; | 返回国家码。 |
**示例**
```js
geolocation.getCountryCode()
.then((result) => {
console.log('promise, getCountryCode: result=' + JSON.stringify(result));
})
.catch((error) => {
console.log('promise, getCountryCode: error=' + JSON.stringify(error));
}); });
``` ```
## geolocation.enableLocationMock<sup>9+</sup>
enableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback&lt;void&gt;) : void;
使能某个场景的位置模拟功能,同一时间只能使能一个场景的位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | 否 | 指示在什么场景下使能位置模拟功能。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var request = {"scenario": 0x0301};
geolocation.enableLocationMock(request, (err, result) => {
if (err) {
console.log('enableLocationMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('enableLocationMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.enableLocationMock<sup>9+</sup>
enableLocationMock(scenario?: LocationRequestScenario) : Promise&lt;void&gt;;
使能某个场景的位置模拟功能,同一时间只能使能一个场景的位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | 否 | 指示使能什么场景的位置模拟功能。如果不携带该参数则表示使能所有场景的位置模拟功能。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var request = {"scenario": 0x0301};
geolocation.enableLocationMock(request)
.then((result) => {
if (result) {
console.log('promise, enableLocationMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, enableLocationMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.disableLocationMock<sup>9+</sup>
disableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback&lt;void&gt;) : void;
去使能位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | 否 | 指示去使能某个场景的位置模拟功能。如果不携带该参数则表示去使能所有场景的位置模拟功能。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var request = {"scenario": 0x0301};
geolocation.disableLocationMock(request, (err, result) => {
if (err) {
console.log('disableLocationMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('disableLocationMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.disableLocationMock<sup>9+</sup>
disableLocationMock(scenario?: LocationRequestScenario) : Promise&lt;void&gt;;
去使能位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | 否 | 指示去使能某个场景的位置模拟功能。如果不携带该参数则表示去使能所有场景的位置模拟功能。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var request = {"scenario": 0x0301};
geolocation.disableLocationMock(request)
.then((result) => {
if (result) {
console.log('promise, disableLocationMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, disableLocationMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.setMockedLocations<sup>9+</sup>
setMockedLocations(config: LocationMockConfig, callback: AsyncCallback&lt;void&gt;) : void;
设置模拟的位置信息,后面会以该接口中携带的时间间隔上报模拟位置。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| config | LocationMockConfig | 是 | 指示位置模拟的配置参数,包含模拟位置上报的时间间隔和模拟位置数组。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var locations = [
{"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}
];
var config = {"timeInterval": 5, "locations": locations};
geolocation.setMockedLocations(config, (err, data) => {
if (err) {
console.log('setMockedLocations: err=' + JSON.stringify(err));
}
if (data) {
console.log('setMockedLocations: data=' + JSON.stringify(data));
}
});
```
## geolocation.setMockedLocations<sup>9+</sup>
setMockedLocations(config: LocationMockConfig) : Promise&lt;void&gt;;
设置模拟的位置信息,后面会以该接口中携带的时间间隔上报模拟位置。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| config | LocationMockConfig | 是 | 指示位置模拟的配置参数,包含模拟位置上报的时间间隔和模拟位置数组。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var locations = [
{"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}
];
var config = {"timeInterval": 5, "locations":locations};
geolocation.setMockedLocations(config)
.then((result) => {
if (result) {
console.log('promise, setMockedLocations: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, setMockedLocations: error=' + JSON.stringify(error));
}
});
```
## geolocation.enableReverseGeocodingMock<sup>9+</sup>
enableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;) : void;
使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
geolocation.enableReverseGeocodingMock((err, data) => {
if (err) {
console.log('enableReverseGeocodingMock: err=' + JSON.stringify(err));
}
if (data) {
console.log('enableReverseGeocodingMock: data=' + JSON.stringify(data));
}
});
```
## geolocation.enableReverseGeocodingMock<sup>9+</sup>
enableReverseGeocodingMock() : Promise&lt;void&gt;;
使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
geolocation.enableReverseGeocodingMock()
.then((result) => {
if (result) {
console.log('promise, enableReverseGeocodingMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, enableReverseGeocodingMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.disableReverseGeocodingMock<sup>9+</sup>
disableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;) : void;
去使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
geolocation.disableReverseGeocodingMock((err, result) => {
if (err) {
console.log('disableReverseGeocodingMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('disableReverseGeocodingMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.disableReverseGeocodingMock<sup>9+</sup>
disableReverseGeocodingMock() : Promise&lt;void&gt;;
去使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
geolocation.disableReverseGeocodingMock()
.then((result) => {
if (result) {
console.log('promise, disableReverseGeocodingMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, disableReverseGeocodingMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.setReverseGeocodingMockInfo<sup>9+</sup>
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;, callback: AsyncCallback&lt;void&gt;) : void;
设置逆地理编码模拟功能的配置信息,包含了位置和地名的对应关系,后续进行逆地理编码查询时如果位置信息位于配置信息中,就返回对应的地名。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;ReverseGeocodingMockInfo&gt; | 是 | 指示逆地理编码模拟功能的配置参数数组。逆地理编码模拟功能的配置参数包含了一个位置和一个地名。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var mockInfos = [
{"location": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geolocation.setReverseGeocodingMockInfo(mockInfos, (err, data) => {
if (err) {
console.log('promise, setReverseGeocodingMockInfo, err:' + JSON.stringify(err));
}
if (data) {
console.log('promise, setReverseGeocodingMockInfo, data:' + JSON.stringify(data));
}
});
```
## geolocation.setReverseGeocodingMockInfo<sup>9+</sup>
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;) : Promise&lt;void&gt;;
设置逆地理编码模拟功能的配置信息,包含了位置和地名的对应关系,后续进行逆地理编码查询时如果位置信息位于配置信息中,就返回对应的地名。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;ReverseGeocodingMockInfo&gt; | 是 | 指示逆地理编码模拟功能的配置信息数组。逆地理编码模拟功能的配置信息包含了一个位置和一个地名。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var mockInfos = [
{"location": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "shanghai", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "beijing", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "shenzhen", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "wuhan", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "chengdu", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geolocation.setReverseGeocodingMockInfo(mockInfos)
.then((result) => {
if (result) {
console.log('promise, setReverseGeocodingMockInfo: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, setReverseGeocodingMockInfo: error=' + JSON.stringify(error));
}
});
```
## LocationRequestPriority ## LocationRequestPriority
...@@ -1225,13 +1841,15 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolea ...@@ -1225,13 +1841,15 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolea
| 名称 | 默认值 | 说明 | | 名称 | 默认值 | 说明 |
| -------- | -------- | -------- | | -------- | -------- | -------- |
| INPUT_PARAMS_ERROR | 101 | 表示输入参数错误。 | | NOT_SUPPORTED<sup>9+</sup> | 100 | 表示该接口功能不支持。 |
| REVERSE_GEOCODE_ERROR | 102 | 表示逆地理编码接口调用失败。 | | INPUT_PARAMS_ERROR<sup>7+</sup> | 101 | 表示输入参数错误。 |
| GEOCODE_ERROR | 103 | 表示地理编码接口调用失败。 | | REVERSE_GEOCODE_ERROR<sup>7+</sup> | 102 | 表示逆地理编码接口调用失败。 |
| LOCATOR_ERROR | 104 | 表示定位失败。 | | GEOCODE_ERROR<sup>7+</sup> | 103 | 表示地理编码接口调用失败。 |
| LOCATION_SWITCH_ERROR | 105 | 表示定位开关。 | | LOCATOR_ERROR<sup>7+</sup> | 104 | 表示定位失败。 |
| LAST_KNOWN_LOCATION_ERROR | 106 | 表示获取上次位置失败。 | | LOCATION_SWITCH_ERROR<sup>7+</sup> | 105 | 表示定位开关。 |
| LOCATION_REQUEST_TIMEOUT_ERROR | 107 | 表示单次定位,没有在指定时间内返回位置。 | | LAST_KNOWN_LOCATION_ERROR<sup>7+</sup> | 106 | 表示获取上次位置失败。 |
| LOCATION_REQUEST_TIMEOUT_ERROR<sup>7+</sup> | 107 | 表示单次定位,没有在指定时间内返回位置。 |
| QUERY_COUNTRY_CODE_ERROR<sup>9+</sup> | 108 | 表示国家码查询失败。 |
## ReverseGeoCodeRequest ## ReverseGeoCodeRequest
...@@ -1279,24 +1897,25 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolea ...@@ -1279,24 +1897,25 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolea
| 名称 | 参数类型 | 必填 | 说明 | | 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| latitude | number | 否 | 表示纬度信息,正值表示北纬,负值表示南纬。 | | latitude<sup>7+</sup> | number | 否 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude | number | 否 | 表示经度信息,正值表示东经,负值表是西经。 | | longitude<sup>7+</sup> | number | 否 | 表示经度信息,正值表示东经,负值表是西经。 |
| locale | string | 否 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 | | locale<sup>7+</sup> | string | 否 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| placeName | string | 否 | 表示地区信息。 | | placeName<sup>7+</sup> | string | 否 | 表示地区信息。 |
| countryCode | string | 否 | 表示国家码信息。 | | countryCode<sup>7+</sup> | string | 否 | 表示国家码信息。 |
| countryName | string | 否 | 表示国家信息。 | | countryName<sup>7+</sup> | string | 否 | 表示国家信息。 |
| administrativeArea | string | 否 | 表示省份区域信息。 | | administrativeArea<sup>7+</sup> | string | 否 | 表示省份区域信息。 |
| subAdministrativeArea | string | 否 | 表示表示子区域信息。 | | subAdministrativeArea<sup>7+</sup> | string | 否 | 表示表示子区域信息。 |
| locality | string | 否 | 表示城市信息。 | | locality<sup>7+</sup> | string | 否 | 表示城市信息。 |
| subLocality | string | 否 | 表示子城市信息。 | | subLocality<sup>7+</sup> | string | 否 | 表示子城市信息。 |
| roadName | string | 否 | 表示路名信息。 | | roadName<sup>7+</sup> | string | 否 | 表示路名信息。 |
| subRoadName | string | 否 | 表示子路名信息。 | | subRoadName<sup>7+</sup> | string | 否 | 表示子路名信息。 |
| premises | string | 否 | 表示门牌号信息。 | | premises<sup>7+</sup> | string | 否 | 表示门牌号信息。 |
| postalCode | string | 否 | 表示邮政编码信息。 | | postalCode<sup>7+</sup> | string | 否 | 表示邮政编码信息。 |
| phoneNumber | string | 否 | 表示联系方式信息。 | | phoneNumber<sup>7+</sup> | string | 否 | 表示联系方式信息。 |
| addressUrl | string | 否 | 表示位置信息附件的网址信息。 | | addressUrl<sup>7+</sup> | string | 否 | 表示位置信息附件的网址信息。 |
| descriptions | Array&lt;string&gt; | 否 | 表示附加的描述信息。 | | descriptions<sup>7+</sup> | Array&lt;string&gt; | 否 | 表示附加的描述信息。 |
| descriptionsSize | number | 否 | 表示附加的描述信息数量。 | | descriptionsSize<sup>7+</sup> | number | 否 | 表示附加的描述信息数量。 |
| isFromMock<sup>9+</sup> | Boolean | 否 | 表示地名信息是否来自于逆地理编码模拟功能。 |
## LocationRequest ## LocationRequest
...@@ -1434,13 +2053,68 @@ GNSS围栏的配置参数。目前只支持圆形围栏。 ...@@ -1434,13 +2053,68 @@ GNSS围栏的配置参数。目前只支持圆形围栏。
| 名称 | 参数类型 | 必填 | 说明 | | 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| latitude | number | 是 | 表示纬度信息,正值表示北纬,负值表示南纬。 | | latitude<sup>7+</sup> | number | 是 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude | number | 是 | 表示经度信息,正值表示东经,负值表是西经。 | | longitude<sup>7+</sup> | number | 是 | 表示经度信息,正值表示东经,负值表是西经。 |
| altitude | number | 是 | 表示高度信息,单位米。 | | altitude<sup>7+</sup> | number | 是 | 表示高度信息,单位米。 |
| accuracy | number | 是 | 表示精度信息,单位米。 | | accuracy<sup>7+</sup> | number | 是 | 表示精度信息,单位米。 |
| speed | number | 是 | 表示速度信息,单位米每秒。 | | speed<sup>7+</sup> | number | 是 | 表示速度信息,单位米每秒。 |
| timeStamp | number | 是 | 表示位置时间戳,UTC格式。 | | timeStamp<sup>7+</sup> | number | 是 | 表示位置时间戳,UTC格式。 |
| direction | number | 是 | 表示航向信息。 | | direction<sup>7+</sup> | number | 是 | 表示航向信息。 |
| timeSinceBoot | number | 是 | 表示位置时间戳,开机时间格式。 | | timeSinceBoot<sup>7+</sup> | number | 是 | 表示位置时间戳,开机时间格式。 |
| additions | Array&lt;string&gt; | 否 | 附加信息。 | | additions<sup>7+</sup> | Array&lt;string&gt; | 否 | 附加信息。 |
| additionSize | number | 否 | 附加信息数量。 | | additionSize<sup>7+</sup> | number | 否 | 附加信息数量。 |
| isFromMock<sup>9+</sup> | Boolean | 否 | 表示位置信息是否来自于位置模拟功能。 |
## ReverseGeocodingMockInfo<sup>9+</sup>
逆地理编码模拟功能的配置信息,包含一个位置信息和一个地名信息。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| location | ReverseGeoCodeRequest | 是 | 表示经纬度信息。 |
| geoAddress | GeoAddress | 是 | 表示地名信息。 |
## LocationMockConfig<sup>9+</sup>
位置模拟功能的配置参数,包含了模拟位置上报的时间间隔和模拟位置数组。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| timeInterval | number | 是 | 表示模拟位置上报的时间间隔,单位是秒。 |
| locations | Array&lt;Location&gt; | 是 | 表示模拟位置数组。 |
## CountryCode<sup>9+</sup>
国家码信息结构体,包含国家码字符串和国家码的来源信息。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| country | string | 是 | 表示国家码字符串。 |
| type | CountryCodeType | 是 | 表示国家码信息来源。 |
## CountryCodeType<sup>9+</sup>
国家码来源类型。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| COUNTRY_CODE_FROM_LOCALE | 1 | 从全球化模块的语言配置信息中获取到的国家码。 |
| COUNTRY_CODE_FROM_SIM | 2 | 从SIM卡中获取到的国家码。 |
| COUNTRY_CODE_FROM_LOCATION | 3 | 基于用户的位置信息,通过逆地理编码查询到的国家码。 |
| COUNTRY_CODE_FROM_NETWORK | 4 | 从蜂窝网络注册信息中获取到的国家码。 |
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册