diff --git a/en/application-dev/reference/apis/js-apis-geolocation.md b/en/application-dev/reference/apis/js-apis-geolocation.md
index 01a012065ab52ac2e7a1dc781b608ec865394c31..d08cc7aafb9e16ecd89533e4a772c18372d23da5 100644
--- a/en/application-dev/reference/apis/js-apis-geolocation.md
+++ b/en/application-dev/reference/apis/js-apis-geolocation.md
@@ -8,8 +8,7 @@ Location services provide basic functions such as GNSS positioning, network posi
## Modules to Import
-
-```
+```js
import geolocation from '@ohos.geolocation';
```
@@ -23,7 +22,8 @@ Registers a listener for location changes with a location request initiated.
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.
| 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 locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
@@ -52,16 +52,17 @@ Unregisters the listener for location changes with the corresponding location re
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
-- Example
+**Example**
- ```
+ ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
@@ -81,18 +82,19 @@ Registers a listener for location service status change events.
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
-- Example
+**Example**
- ```
+ ```js
var locationServiceState = (state) => {
- console.log('locationServiceState: ' + state);
+ console.log('locationServiceState: ' + JSON.stringify(state));
}
geolocation.on('locationServiceState', locationServiceState);
```
@@ -108,18 +110,19 @@ Unregisters the listener for location service status change events.
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
-- Example
+**Example**
- ```
+ ```js
var locationServiceState = (state) => {
- console.log('locationServiceState: state: ' + state);
+ console.log('locationServiceState: state: ' + JSON.stringify(state));
}
geolocation.on('locationServiceState', locationServiceState);
geolocation.off('locationServiceState', locationServiceState);
@@ -136,7 +139,8 @@ Registers a listener for cached GNSS location reports.
**System capability**: SystemCapability.Location.Location.Gnss
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.
| callback | Callback<boolean> | Yes| Callback used to return cached GNSS locations.|
-- Example
+**Example**
- ```
+ ```js
var cachedLocationsCb = (locations) => {
- console.log('cachedGnssLocationsReporting: locations: ' + locations);
+ console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
}
var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
@@ -165,18 +169,19 @@ Unregisters the listener for cached GNSS location reports.
**System capability**: SystemCapability.Location.Location.Gnss
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
-- Example
+**Example**
- ```
+ ```js
var cachedLocationsCb = (locations) => {
- console.log('cachedGnssLocationsReporting: locations: ' + locations);
+ console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
}
var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
@@ -194,18 +199,19 @@ Registers a listener for GNSS satellite status change events.
**System capability**: SystemCapability.Location.Location.Gnss
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
-- Example
+**Example**
- ```
+ ```js
var gnssStatusCb = (satelliteStatusInfo) => {
- console.log('gnssStatusChange: ' + satelliteStatusInfo);
+ console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
geolocation.on('gnssStatusChange', gnssStatusCb);
```
@@ -221,17 +227,18 @@ Unregisters the listener for GNSS satellite status change events.
**System capability**: SystemCapability.Location.Location.Gnss
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
-- Example
+**Example**
- ```
+ ```js
var gnssStatusCb = (satelliteStatusInfo) => {
- console.log('gnssStatusChange: ' + satelliteStatusInfo);
+ console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
geolocation.on('gnssStatusChange', gnssStatusCb);
geolocation.off('gnssStatusChange', gnssStatusCb);
@@ -248,18 +255,19 @@ Registers a listener for GNSS NMEA message change events.
**System capability**: SystemCapability.Location.Location.Gnss
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
-- Example
+**Example**
- ```
+ ```js
var nmeaCb = (str) => {
- console.log('nmeaMessageChange: ' + str);
+ console.log('nmeaMessageChange: ' + JSON.stringify(str));
}
geolocation.on('nmeaMessageChange', nmeaCb );
```
@@ -275,18 +283,19 @@ Unregisters the listener for GNSS NMEA message change events.
**System capability**: SystemCapability.Location.Location.Gnss
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.|
-- Example
+**Example**
- ```
+ ```js
var nmeaCb = (str) => {
- console.log('nmeaMessageChange: ' + str);
+ console.log('nmeaMessageChange: ' + JSON.stringify(str));
}
geolocation.on('nmeaMessageChange', nmeaCb);
geolocation.off('nmeaMessageChange', nmeaCb);
@@ -303,7 +312,8 @@ Registers a listener for status change events of the specified geofence.
**System capability**: SystemCapability.Location.Location.Geofence
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| 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.
| want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
-- Example
+**Example**
- ```
- import WantAgent from '@ohos.wantAgent';
- import { OperationType, WantAgentFlags } from '@ohos.wantagent';
- // WantAgent object
- var wantAgent;
- // getWantAgent callback
- function getWantAgentCallback(err, data) {
- console.info("==========================>getWantAgentCallback=======================>");
- if (err.code == 0) {
- wantAgent = data;
- } else {
- console.info('----getWantAgent failed!----');
- }
- }
- // WantAgentInfo object
- var wantAgentInfo = {
+ ```js
+ import geolocation from '@ohos.geolocation';
+ import wantAgent from '@ohos.wantAgent';
+
+ let wantAgentInfo = {
wants: [
{
- deviceId: "deviceId",
- bundleName: "com.neu.setResultOnAbilityResultTest1",
- abilityName: "com.example.test.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "com.example.myapplication.MainAbility"
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,
- wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
- }
- WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
- var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
- geolocation.on('fenceStatusChange', requestInfo, wantAgent);
+ wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
+ };
+
+ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
+ var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
+ geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
+ });
```
@@ -370,60 +357,91 @@ Unregisters the listener for status change events of the specified geofence.
**System capability**: SystemCapability.Location.Location.Geofence
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.|
| request | GeofenceRequest | Yes| Geofencing request.|
| want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
-- Example
+**Example**
- ```
- import WantAgent from '@ohos.wantAgent';
- import { OperationType, WantAgentFlags } from '@ohos.wantagent';
- // WantAgent object
- var wantAgent;
- // getWantAgent callback
- function getWantAgentCallback(err, data) {
- console.info("==========================>getWantAgentCallback=======================>");
- if (err.code == 0) {
- wantAgent = data;
- } else {
- console.info('----getWantAgent failed!----');
- }
- }
- // WantAgentInfo object
- var wantAgentInfo = {
+ ```js
+ import geolocation from '@ohos.geolocation';
+ import wantAgent from '@ohos.wantAgent';
+
+ let wantAgentInfo = {
wants: [
{
- deviceId: "deviceId",
- bundleName: "com.neu.setResultOnAbilityResultTest1",
- abilityName: "com.example.test.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "com.example.myapplication.MainAbility"
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,
- wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
+ wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
+ };
+
+ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
+ var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
+ geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
+ geolocation.off('fenceStatusChange', requestInfo, wantAgentObj);
+ });
+ ```
+
+
+## geolocation.on('countryCodeChange')9+
+
+on(type: 'countryCodeChange', callback: Callback<CountryCode>) : 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<CountryCode> | 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')9+
+
+off(type: 'countryCodeChange', callback?: Callback<CountryCode>) : 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<CountryCode> | Yes | Callback is used to receive the country code information report. |
+
+
+**Example**
+
+ ```js
+ var callback = (code) => {
+ console.log('countryCodeChange: ' + JSON.stringify(code));
}
- WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
- var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
- geolocation.on('fenceStatusChange', requestInfo, wantAgent);
- geolocation.off('fenceStatusChange', requestInfo, wantAgent);
+ 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
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.|
| callback | AsyncCallback<[Location](#location)> | Yes| Callback used to return the current location.|
-- Example
+**Example**
- ```
+ ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
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(locationChange);
@@ -467,22 +491,24 @@ Obtains the current location. This API uses a promise to return the result.
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.|
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<[Location](#location)> | Promise used to return the current location.|
-- Example
+**Example**
- ```
+ ```js
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));
});
```
@@ -498,17 +524,23 @@ Obtains the previous location. This API uses an asynchronous callback to return
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<[Location](#location)> | Yes| Callback used to return the previous location.|
-- Example
+**Example**
- ```
+ ```js
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.
**System capability**: SystemCapability.Location.Location.Core
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<[Location](#location)> | Promise used to return the previous location.|
-- Example
+**Example**
- ```
+ ```js
geolocation.getLastLocation().then((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
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | Yes| Callback used to return the location service status.|
-
-- Example
+**Example**
- ```
+ ```js
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
**System capability**: SystemCapability.Location.Location.Core
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the location service status.|
-- Example
+**Example**
- ```
+ ```js
geolocation.isLocationEnabled().then((result) => {
console.log('promise, isLocationEnabled: ' + result);
});
@@ -599,17 +638,22 @@ Requests to enable the location service. This API uses an asynchronous callback
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | Yes| Callback used to return the location service status.|
-
-- Example
+**Example**
- ```
+ ```js
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
**System capability**: SystemCapability.Location.Location.Core
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the location service status.|
-
-- Example
+**Example**
- ```
+ ```js
geolocation.requestEnableLocation().then((result) => {
- console.log('promise, requestEnableLocation: ' + result);
+ console.log('promise, requestEnableLocation: ' + JSON.stringify(result));
});
```
@@ -645,23 +689,28 @@ enableLocation(callback: AsyncCallback<boolean>) : void;
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
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | Yes| Callback used to return the location service status.|
-
-- Example
+**Example**
- ```
+ ```js
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<boolean>
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
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the location service status.|
-
-- Example
+**Example**
- ```
+ ```js
geolocation.enableLocation().then((result) => {
- console.log('promise, enableLocation: ' + result);
+ console.log('promise, enableLocation: ' + JSON.stringify(result));
});
```
@@ -698,23 +747,28 @@ disableLocation(callback: AsyncCallback<boolean>) : void;
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
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | Yes| Callback used to return the location service status.|
-
-- Example
+**Example**
- ```
+ ```js
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<boolean>
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
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the location service status.|
-
-- Example
+**Example**
- ```
+ ```js
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
**System capability**: SystemCapability.Location.Location.Geocoder
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | Yes| Callback used to return the (reverse) geocoding service status.|
-
-- Example
+**Example**
- ```
+ ```js
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
**System capability**: SystemCapability.Location.Location.Geocoder
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the (reverse) geocoding service status.|
-
-- Example
+**Example**
- ```
+ ```js
geolocation.isGeoServiceAvailable().then((result) => {
- console.log('promise, isGeoServiceAvailable: ' + result);
+ console.log('promise, isGeoServiceAvailable: ' + JSON.stringify(result));
});
```
-
## geolocation.getAddressesFromLocation
getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>) : void
@@ -806,18 +864,24 @@ Converts coordinates into geographic description through reverse geocoding. This
**System capability**: SystemCapability.Location.Location.Geocoder
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
| callback | AsyncCallback<Array<[GeoAddress](#geoaddress)>> | Yes| Callback used to return the reverse geocoding result.|
-- Example
+**Example**
- ```
+ ```js
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
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
**System capability**: SystemCapability.Location.Location.Geocoder
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<Array<[GeoAddress](#geoaddress)>> | Promise used to return the reverse geocoding result.|
-- Example
+**Example**
- ```
+ ```js
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
console.log('getAddressesFromLocation: ' + JSON.stringify(data));
@@ -862,19 +928,24 @@ Converts geographic description into coordinates through geocoding. This API use
**System capability**: SystemCapability.Location.Location.Geocoder
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
| callback | AsyncCallback<Array<[GeoAddress](#geoaddress)>> | Yes| Callback used to return the geocoding result.|
-
-- Example
+**Example**
- ```
+ ```js
var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
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
**System capability**: SystemCapability.Location.Location.Geocoder
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<Array<[GeoAddress](#geoaddress)>> | Callback used to return the geocoding result.|
-- Example
+**Example**
- ```
+ ```js
var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
@@ -909,7 +982,6 @@ Converts geographic description into coordinates through geocoding. This API use
```
-
## geolocation.getCachedGnssLocationsSize8+
getCachedGnssLocationsSize(callback: AsyncCallback<number>) : void;
@@ -920,16 +992,22 @@ Obtains the number of cached GNSS locations.
**System capability**: SystemCapability.Location.Location.Gnss
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<number> | Yes| Callback used to return the number of cached GNSS locations. |
-- Example
+**Example**
- ```
+ ```js
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.
**System capability**: SystemCapability.Location.Location.Gnss
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<number> | Promise used to return the number of cached GNSS locations.|
-- Example
+**Example**
- ```
+ ```js
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.
**System capability**: SystemCapability.Location.Location.Gnss
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | Yes| Callback used to return the operation result.|
-- Example
+**Example**
- ```
+ ```js
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.
**System capability**: SystemCapability.Location.Location.Gnss
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<boolean> | Promise used to return the operation result.|
-- Example
+**Example**
- ```
+ ```js
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
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| command | LocationCommand | Yes| Extended command (string) to be sent.|
| callback | AsyncCallback<boolean> | Yes| Callback used to return the operation result.|
-- Example
+**Example**
- ```
+ ```js
var requestInfo = {'scenario': 0x301, 'command': "command_1"};
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
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| command | LocationCommand | Yes| Extended command (string) to be sent.|
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<boolean> | Callback used to return the operation result.|
-- Example
+**Example**
- ```
+ ```js
var requestInfo = {'scenario': 0x301, 'command': "command_1"};
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
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
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| 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.|
| callback | AsyncCallback<boolean> | 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) => {
- 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<boolean>
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
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| 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.|
-- Return value
+**Return value**
+
| Name| Description|
| -------- | -------- |
| Promise<boolean> | Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
-- Example
+**Example**
- ```
+ ```js
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
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
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| 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.|
| isConfirmed | boolean | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
| callback | AsyncCallback<boolean> | Yes| Callback used to return the operation result.|
-- Example
+**Example**
- ```
+ ```js
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
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
**System capability**: SystemCapability.Location.Location.Core
-- Parameters
+**Parameters**
+
| 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.|
| 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|
| -------- | -------- |
| Promise<boolean> | Callback used to return the operation result.|
-- Example
+**Example**
- ```
+ ```js
geolocation.setLocationPrivacyConfirmStatus(1, true).then((result) => {
- console.log('promise, setLocationPrivacyConfirmStatus: ' + result);
+ console.log('promise, setLocationPrivacyConfirmStatus: ' + JSON.stringify(result));
+ });
+ ```
+
+
+## geolocation.getCountryCode9+
+
+getCountryCode(callback: AsyncCallback<CountryCode>) : void;
+
+Query the current country code.
+
+**System capability**: SystemCapability.Location.Location.Core
+
+**Parameters**
+
+ | Name| Type| Mandatory| Description|
+ | -------- | -------- | -------- | -------- |
+ | callback | AsyncCallback<CountryCode> | 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.getCountryCode9+
+
+getCountryCode() : Promise<CountryCode>;
+
+Query the current country code.
+
+**System capability**: SystemCapability.Location.Location.Core
+
+**Parameters**
+
+None
+
+**Return value**
+
+ | Name| Description|
+ | -------- | -------- |
+ | Promise<CountryCode> | 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.enableLocationMock9+
+
+enableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback<void>) : 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<void> | 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.enableLocationMock9+
+
+enableLocationMock(scenario?: LocationRequestScenario) : Promise<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 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<void> | 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.disableLocationMock9+
+
+disableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback<void>) : 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<void> | 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.disableLocationMock9+
+
+disableLocationMock(scenario?: LocationRequestScenario) : Promise<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. |
+
+**Return value**
+
+ | Name| Description|
+ | -------- | -------- |
+ | Promise<void> | 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.setMockedLocations9+
+
+setMockedLocations(config: LocationMockConfig, callback: AsyncCallback<void>) : 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<void> | 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.setMockedLocations9+
+
+setMockedLocations(config: LocationMockConfig) : Promise<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. |
+
+**Return value**
+
+ | Name| Description|
+ | -------- | -------- |
+ | Promise<void> | 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.enableReverseGeocodingMock9+
+
+enableReverseGeocodingMock(callback: AsyncCallback<void>) : 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<void> | 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.enableReverseGeocodingMock9+
+
+enableReverseGeocodingMock() : Promise<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**:
+
+None
+
+**Return value**
+
+ | Name| Description|
+ | -------- | -------- |
+ | Promise<void> | 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.disableReverseGeocodingMock9+
+
+disableReverseGeocodingMock(callback: AsyncCallback<void>) : 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<void> | 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.disableReverseGeocodingMock9+
+
+disableReverseGeocodingMock() : Promise<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**:
+
+None
+
+**Return value**
+
+ | Name| Description|
+ | -------- | -------- |
+ | Promise<void> | 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.setReverseGeocodingMockInfo9+
+
+setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>, callback: AsyncCallback<void>) : 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<ReverseGeocodingMockInfo> | 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<void> | 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.setReverseGeocodingMockInfo9+
+
+setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>) : Promise<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<ReverseGeocodingMockInfo> | 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<void> | 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
@@ -1225,13 +1841,15 @@ Enumerates error codes of the location service.
| Name| Default Value| Description|
| -------- | -------- | -------- |
-| INPUT_PARAMS_ERROR | 101 | Incorrect input parameters.|
-| REVERSE_GEOCODE_ERROR | 102 | Failed to call the reverse geocoding API.|
-| GEOCODE_ERROR | 103 | Failed to call the geocoding API.|
-| LOCATOR_ERROR | 104 | Failed to obtain the location.|
-| LOCATION_SWITCH_ERROR | 105 | Failed to change the location service switch.|
-| LAST_KNOWN_LOCATION_ERROR | 106 | Failed to obtain the previous location.|
-| LOCATION_REQUEST_TIMEOUT_ERROR | 107 | Failed to obtain the location within the specified time.|
+| NOT_SUPPORTED9+ | 100 | Indicates that the interface function is not supported. |
+| INPUT_PARAMS_ERROR7+ | 101 | Incorrect input parameters.|
+| REVERSE_GEOCODE_ERROR7+ | 102 | Failed to call the reverse geocoding API.|
+| GEOCODE_ERROR7+ | 103 | Failed to call the geocoding API.|
+| LOCATOR_ERROR7+ | 104 | Failed to obtain the location.|
+| LOCATION_SWITCH_ERROR7+ | 105 | Failed to change the location service switch.|
+| LAST_KNOWN_LOCATION_ERROR7+ | 106 | Failed to obtain the previous location.|
+| LOCATION_REQUEST_TIMEOUT_ERROR7+ | 107 | Failed to obtain the location within the specified time.|
+| QUERY_COUNTRY_CODE_ERROR9+ | 108 | Indicates that the country code query failed. |
## ReverseGeoCodeRequest
@@ -1279,24 +1897,25 @@ Defines a geographic location.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| latitude | 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 .|
-| locale | string | No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
-| placeName | string | No| Landmark of the location.|
-| countryCode | string | No| Country code.|
-| countryName | string | No| Country name.|
-| administrativeArea | string | No| Administrative region name.|
-| subAdministrativeArea | string | No| Sub-administrative region name.|
-| locality | string | No| Locality information. |
-| subLocality | string | No| Sub-locality information. |
-| roadName | string | No| Road name.|
-| subRoadName | string | No| Auxiliary road information.|
-| premises | string | No| House information.|
-| postalCode | string | No| Postal code.|
-| phoneNumber | string | No| Phone number.|
-| addressUrl | string | No| Website URL.|
-| descriptions | Array<string> | No| Additional description.|
-| descriptionsSize | number | No| Total number of additional descriptions.|
+| latitude7+ | number | No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
+| longitude7+ | number | No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
+| locale7+ | string | No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
+| placeName7+ | string | No| Landmark of the location.|
+| countryCode7+ | string | No| Country code.|
+| countryName7+ | string | No| Country name.|
+| administrativeArea7+ | string | No| Administrative region name.|
+| subAdministrativeArea7+ | string | No| Sub-administrative region name.|
+| locality7+ | string | No| Locality information. |
+| subLocality7+ | string | No| Sub-locality information. |
+| roadName7+ | string | No| Road name.|
+| subRoadName7+ | string | No| Auxiliary road information.|
+| premises7+ | string | No| House information.|
+| postalCode7+ | string | No| Postal code.|
+| phoneNumber7+ | string | No| Phone number.|
+| addressUrl7+ | string | No| Website URL.|
+| descriptions7+ | Array<string> | No| Additional description.|
+| descriptionsSize7+ | number | No| Total number of additional descriptions.|
+| isFromMock9+ | Boolean | No | Indicates whether the geographical name information comes from the reverse geocoding simulation function. |
## LocationRequest
@@ -1434,13 +2053,68 @@ Defines a location.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
-| latitude | 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 .|
-| altitude | number | Yes| Location altitude, in meters.|
-| accuracy | number | Yes| Location accuracy, in meters.|
-| speed | number | Yes| Speed, in m/s.|
-| timeStamp | number | Yes| Location timestamp in the UTC format.|
-| direction | number | Yes| Direction information.|
-| timeSinceBoot | number | Yes| Location timestamp since boot.|
-| additions | Array<string> | No| Additional information.|
-| additionSize | number | No| Number of additional descriptions.|
+| latitude7+ | number | Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
+| longitude7+ | number | Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
+| altitude7+ | number | Yes| Location altitude, in meters.|
+| accuracy7+ | number | Yes| Location accuracy, in meters.|
+| speed7+ | number | Yes| Speed, in m/s.|
+| timeStamp7+ | number | Yes| Location timestamp in the UTC format.|
+| direction7+ | number | Yes| Direction information.|
+| timeSinceBoot7+ | number | Yes| Location timestamp since boot.|
+| additions7+ | Array<string> | No| Additional information.|
+| additionSize7+ | number | No| Number of additional descriptions.|
+| isFromMock9+ | Boolean | No | Indicates whether the location information comes from the location simulation function. |
+
+
+## ReverseGeocodingMockInfo9+
+
+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. |
+
+
+## LocationMockConfig9+
+
+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<Location> | Yes | Represents an array of mocked locations. |
+
+
+## CountryCode9+
+
+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. |
+
+
+## CountryCodeType9+
+
+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
diff --git a/zh-cn/application-dev/reference/apis/js-apis-geolocation.md b/zh-cn/application-dev/reference/apis/js-apis-geolocation.md
index 77ef5727a7148b5bcb46644f777524cc85862bb7..af1e4a30179d3e012aabc248ccd460f15894b34a 100644
--- a/zh-cn/application-dev/reference/apis/js-apis-geolocation.md
+++ b/zh-cn/application-dev/reference/apis/js-apis-geolocation.md
@@ -8,8 +8,7 @@
## 导入模块
-
-```
+```js
import geolocation from '@ohos.geolocation';
```
@@ -23,7 +22,8 @@ on(type: 'locationChange', request: LocationRequest, callback: Callback<Locat
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“locationChange”,表示位置变化。 |
@@ -31,9 +31,9 @@ on(type: 'locationChange', request: LocationRequest, callback: Callback<Locat
| callback | Callback<[Location](#location)> | 是 | 接收位置变化状态变化监听。 |
-- 示例:
+**示例**
- ```
+ ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
@@ -52,16 +52,17 @@ off(type: 'locationChange', callback?: Callback<Location>) : void
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“locationChange”,表示位置变化。 |
| callback | Callback<[Location](#location)> | 否 | 接收位置变化状态变化监听。 |
-- 示例:
+**示例**
- ```
+ ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
@@ -81,18 +82,19 @@ on(type: 'locationServiceState', callback: Callback<boolean>) : void
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“locationServiceState”,表示位置服务状态。 |
| callback | Callback<boolean> | 是 | 接收位置服务状态变化监听。 |
-- 示例:
+**示例**
- ```
+ ```js
var locationServiceState = (state) => {
- console.log('locationServiceState: ' + state);
+ console.log('locationServiceState: ' + JSON.stringify(state));
}
geolocation.on('locationServiceState', locationServiceState);
```
@@ -108,18 +110,19 @@ off(type: 'locationServiceState', callback?: Callback<boolean>) : void;
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“locationServiceState”,表示位置服务状态。 |
| callback | Callback<boolean> | 否 | 接收位置服务状态变化监听。 |
-- 示例:
+**示例**
- ```
+ ```js
var locationServiceState = (state) => {
- console.log('locationServiceState: state: ' + state);
+ console.log('locationServiceState: state: ' + JSON.stringify(state));
}
geolocation.on('locationServiceState', locationServiceState);
geolocation.off('locationServiceState', locationServiceState);
@@ -136,7 +139,8 @@ on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, ca
**系统能力**:SystemCapability.Location.Location.Gnss
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“cachedGnssLocationsReporting”,表示GNSS缓存定位结果上报。 |
@@ -144,11 +148,11 @@ on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, ca
| callback | Callback<boolean> | 是 | 接收GNSS缓存位置上报。 |
-- 示例:
+**示例**
- ```
+ ```js
var cachedLocationsCb = (locations) => {
- console.log('cachedGnssLocationsReporting: locations: ' + locations);
+ console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
}
var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
@@ -165,18 +169,19 @@ off(type: 'cachedGnssLocationsReporting', callback?: Callback<Array<Locati
**系统能力**:SystemCapability.Location.Location.Gnss
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“cachedGnssLocationsReporting”,表示GNSS缓存定位结果上报。 |
| callback | Callback<boolean> | 否 | 接收GNSS缓存位置上报。 |
-- 示例:
+**示例**
- ```
+ ```js
var cachedLocationsCb = (locations) => {
- console.log('cachedGnssLocationsReporting: locations: ' + locations);
+ console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
}
var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
@@ -194,18 +199,19 @@ on(type: 'gnssStatusChange', callback: Callback<SatelliteStatusInfo>) : vo
**系统能力**:SystemCapability.Location.Location.Gnss
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“gnssStatusChange”,表示订阅GNSS卫星状态信息上报。 |
| callback | Callback<SatelliteStatusInfo> | 是 | 接收GNSS卫星状态信息上报。 |
-- 示例:
+**示例**
- ```
+ ```js
var gnssStatusCb = (satelliteStatusInfo) => {
- console.log('gnssStatusChange: ' + satelliteStatusInfo);
+ console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
geolocation.on('gnssStatusChange', gnssStatusCb);
```
@@ -221,17 +227,18 @@ off(type: 'gnssStatusChange', callback?: Callback<SatelliteStatusInfo>) :
**系统能力**:SystemCapability.Location.Location.Gnss
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“gnssStatusChange”,表示订阅GNSS卫星状态信息上报。 |
| callback | Callback<SatelliteStatusInfo> | 否 | 接收GNSS卫星状态信息上报。 |
-- 示例:
+**示例**
- ```
+ ```js
var gnssStatusCb = (satelliteStatusInfo) => {
- console.log('gnssStatusChange: ' + satelliteStatusInfo);
+ console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
geolocation.on('gnssStatusChange', gnssStatusCb);
geolocation.off('gnssStatusChange', gnssStatusCb);
@@ -248,18 +255,19 @@ on(type: 'nmeaMessageChange', callback: Callback<string>) : void;
**系统能力**:SystemCapability.Location.Location.Gnss
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“nmeaMessageChange”,表示订阅GNSS NMEA信息上报。 |
| callback | Callback<string> | 是 | 接收GNSS NMEA信息上报。 |
-- 示例:
+**示例**
- ```
+ ```js
var nmeaCb = (str) => {
- console.log('nmeaMessageChange: ' + str);
+ console.log('nmeaMessageChange: ' + JSON.stringify(str));
}
geolocation.on('nmeaMessageChange', nmeaCb );
```
@@ -275,18 +283,19 @@ off(type: 'nmeaMessageChange', callback?: Callback<string>) : void;
**系统能力**:SystemCapability.Location.Location.Gnss
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“nmeaMessageChange”,表示订阅GNSS NMEA信息上报。 |
| callback | Callback<string> | 否 | 接收GNSS NMEA信息上报。 |
-- 示例:
+**示例**
- ```
+ ```js
var nmeaCb = (str) => {
- console.log('nmeaMessageChange: ' + str);
+ console.log('nmeaMessageChange: ' + JSON.stringify(str));
}
geolocation.on('nmeaMessageChange', nmeaCb);
geolocation.off('nmeaMessageChange', nmeaCb);
@@ -303,7 +312,8 @@ on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void;
**系统能力**:SystemCapability.Location.Location.Geofence
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“fenceStatusChange”,表示订阅围栏事件上报。 |
@@ -311,52 +321,29 @@ on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void;
| want | WantAgent | 是 | 用于接收地理围栏事件上报(进出围栏)。 |
-- 示例:
+**示例**
- ```
- import WantAgent from '@ohos.wantAgent';
- import { OperationType, WantAgentFlags } from '@ohos.wantagent';
- //wantAgent对象
- var wantAgent;
- //getWantAgent回调
- function getWantAgentCallback(err, data) {
- console.info("==========================>getWantAgentCallback=======================>");
- if (err.code == 0) {
- wantAgent = data;
- } else {
- console.info('----getWantAgent failed!----');
- }
- }
- //WantAgentInfo对象
- var wantAgentInfo = {
+ ```js
+ import geolocation from '@ohos.geolocation';
+ import wantAgent from '@ohos.wantAgent';
+
+ let wantAgentInfo = {
wants: [
{
- deviceId: "deviceId",
- bundleName: "com.neu.setResultOnAbilityResultTest1",
- abilityName: "com.example.test.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "com.example.myapplication.MainAbility"
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,
- wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
- }
- WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
- var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
- geolocation.on('fenceStatusChange', requestInfo, wantAgent);
+ wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
+ };
+
+ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
+ var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
+ geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
+ });
```
@@ -370,60 +357,91 @@ off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void
**系统能力**:SystemCapability.Location.Location.Geofence
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“fenceStatusChange”,表示订阅围栏事件上报。 |
| request | GeofenceRequest | 是 | 围栏的配置参数。 |
| want | WantAgent | 是 | 用于接收地理围栏事件上报(进出围栏)。 |
-- 示例:
+**示例**
- ```
- import WantAgent from '@ohos.wantAgent';
- import { OperationType, WantAgentFlags } from '@ohos.wantagent';
- //wantAgent对象
- var wantAgent;
- //getWantAgent回调
- function getWantAgentCallback(err, data) {
- console.info("==========================>getWantAgentCallback=======================>");
- if (err.code == 0) {
- wantAgent = data;
- } else {
- console.info('----getWantAgent failed!----');
- }
- }
- //WantAgentInfo对象
- var wantAgentInfo = {
+ ```js
+ import geolocation from '@ohos.geolocation';
+ import wantAgent from '@ohos.wantAgent';
+
+ let wantAgentInfo = {
wants: [
{
- deviceId: "deviceId",
- bundleName: "com.neu.setResultOnAbilityResultTest1",
- abilityName: "com.example.test.MainAbility",
+ bundleName: "com.example.myapplication",
+ abilityName: "com.example.myapplication.MainAbility"
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,
- wantAgentFlags:[WantAgentFlags.UPDATE_PRESENT_FLAG]
+ wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
+ };
+
+ wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
+ var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
+ geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
+ geolocation.off('fenceStatusChange', requestInfo, wantAgentObj);
+ });
+ ```
+
+
+## geolocation.on('countryCodeChange')9+
+
+on(type: 'countryCodeChange', callback: Callback<CountryCode>) : void;
+
+订阅国家码信息上报事件。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示订阅国家码信息上报。 |
+ | callback | Callback<CountryCode> | 是 | 接收国家码信息上报。 |
+
+
+**示例**
+
+ ```js
+ var callback = (code) => {
+ console.log('countryCodeChange: ' + JSON.stringify(code));
+ }
+ geolocation.on('countryCodeChange', callback);
+ ```
+
+
+## geolocation.off('countryCodeChange')9+
+
+off(type: 'countryCodeChange', callback?: Callback<CountryCode>) : void;
+
+取消订阅国家码上报事件。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示取消订阅国家码信息上报。 |
+ | callback | Callback<CountryCode> | 是 | 接收国家码信息上报。 |
+
+
+**示例**
+
+ ```js
+ var callback = (code) => {
+ console.log('countryCodeChange: ' + JSON.stringify(code));
}
- WantAgent.getWantAgent(wantAgentInfo, getWantAgentCallback)
- var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
- geolocation.on('fenceStatusChange', requestInfo, wantAgent);
- geolocation.off('fenceStatusChange', requestInfo, wantAgent);
+ geolocation.on('countryCodeChange', callback);
+ geolocation.off('countryCodeChange', callback);
```
@@ -438,18 +456,24 @@ getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback<L
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| request | [CurrentLocationRequest](#currentlocationrequest) | 否 | 设置位置请求参数。 |
| callback | AsyncCallback<[Location](#location)> | 是 | 用来接收位置信息的回调。 |
-- 示例:
+**示例**
- ```
+ ```js
var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
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(locationChange);
@@ -467,22 +491,24 @@ getCurrentLocation(request?: CurrentLocationRequest) : Promise<Location>
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| request | [CurrentLocationRequest](#currentlocationrequest) | 否 | 设置位置请求参数。 |
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<[Location](#location)> | 返回位置信息。 |
-- 示例:
+**示例**
- ```
+ ```js
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));
});
```
@@ -498,17 +524,23 @@ getLastLocation(callback: AsyncCallback<Location>) : void
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<[Location](#location)> | 是 | 用来接收上次位置的回调。 |
-- 示例:
+**示例**
- ```
+ ```js
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<Location>
**系统能力**:SystemCapability.Location.Location.Core
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<[Location](#location)> | 返回上次位置信息。 |
-- 示例:
+**示例**
- ```
+ ```js
geolocation.getLastLocation().then((result) => {
console.log('getLastLocation: result: ' + JSON.stringify(result));
});
@@ -549,17 +582,22 @@ isLocationEnabled(callback: AsyncCallback<boolean>) : void
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | 是 | 用来接收位置服务状态的回调。 |
-
-- 示例:
+**示例**
- ```
+ ```js
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<boolean>
**系统能力**:SystemCapability.Location.Location.Core
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<boolean> | 返回位置服务是否可用的状态。 |
-- 示例:
+**示例**
- ```
+ ```js
geolocation.isLocationEnabled().then((result) => {
- console.log('promise, isLocationEnabled: ' + result);
+ console.log('promise, isLocationEnabled: ' + JSON.stringify(result));
});
```
@@ -599,17 +638,22 @@ requestEnableLocation(callback: AsyncCallback<boolean>) : void
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | 是 | 用来接收位置服务状态的回调。 |
-
-- 示例:
+**示例**
- ```
+ ```js
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<boolean>
**系统能力**:SystemCapability.Location.Location.Core
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<boolean> | 返回位置服务是否可用。 |
-
-- 示例:
+**示例**
- ```
+ ```js
geolocation.requestEnableLocation().then((result) => {
- console.log('promise, requestEnableLocation: ' + result);
+ console.log('promise, requestEnableLocation: ' + JSON.stringify(result));
});
```
@@ -647,21 +691,26 @@ enableLocation(callback: AsyncCallback<boolean>) : void;
**系统API**:此接口为系统接口,三方应用不支持调用。
-**需要权限**:ohos.permission.LOCATION
+**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | 是 | 用来接收位置服务状态的回调。 |
-
-- 示例:
+**示例**
- ```
+ ```js
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<boolean>
**系统API**:此接口为系统接口,三方应用不支持调用。
-**需要权限**:ohos.permission.LOCATION
+**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<boolean> | 返回位置服务是否可用。 |
-
-- 示例:
+**示例**
- ```
+ ```js
geolocation.enableLocation().then((result) => {
- console.log('promise, enableLocation: ' + result);
+ console.log('promise, enableLocation: ' + JSON.stringify(result));
});
```
@@ -700,21 +749,26 @@ disableLocation(callback: AsyncCallback<boolean>) : void;
**系统API**:此接口为系统接口,三方应用不支持调用。
-**需要权限**:ohos.permission.LOCATION
+**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | 是 | 用来接收位置服务状态的回调。 |
-
-- 示例:
+**示例**
- ```
+ ```js
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<boolean>
**系统API**:此接口为系统接口,三方应用不支持调用。
-**需要权限**:ohos.permission.LOCATION
+**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<boolean> | 返回位置服务是否可用。 |
-
-- 示例:
+**示例**
- ```
+ ```js
geolocation.disableLocation().then((result) => {
- console.log('promise, disableLocation: ' + result);
+ console.log('promise, disableLocation: ' + JSON.stringify(result));
});
```
@@ -755,17 +809,22 @@ isGeoServiceAvailable(callback: AsyncCallback<boolean>) : void
**系统能力**:SystemCapability.Location.Location.Geocoder
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | 是 | 用来接收地理编码服务状态的回调。 |
-
-- 示例:
+**示例**
- ```
+ ```js
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<boolean>
**系统能力**:SystemCapability.Location.Location.Geocoder
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<boolean> | 返回地理编码服务是否可用的状态。 |
-
-- 示例:
+**示例**
- ```
+ ```js
geolocation.isGeoServiceAvailable().then((result) => {
- console.log('promise, isGeoServiceAvailable: ' + result);
+ console.log('promise, isGeoServiceAvailable: ' + JSON.stringify(result));
});
```
-
## geolocation.getAddressesFromLocation
getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>) : void
@@ -806,18 +864,24 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback
**系统能力**:SystemCapability.Location.Location.Geocoder
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| request | [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 设置逆地理编码请求的相关参数。 |
| callback | AsyncCallback<Array<[GeoAddress](#geoaddress)>> | 是 | 设置接收逆地理编码请求的回调参数。 |
-- 示例:
+**示例**
- ```
+ ```js
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
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<Array<G
**系统能力**:SystemCapability.Location.Location.Geocoder
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| request | [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 设置逆地理编码请求的相关参数。 |
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<Array<[GeoAddress](#geoaddress)>> | 返回地理描述信息。 |
-- 示例:
+**示例**
- ```
+ ```js
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
console.log('getAddressesFromLocation: ' + JSON.stringify(data));
@@ -862,19 +928,24 @@ getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback<
**系统能力**:SystemCapability.Location.Location.Geocoder
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| request | [GeoCodeRequest](#geocoderequest) | 是 | 设置地理编码请求的相关参数。 |
| callback | AsyncCallback<Array<[GeoAddress](#geoaddress)>> | 是 | 设置接收地理编码请求的回调参数。 |
-
-- 示例:
+**示例**
- ```
+ ```js
var geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
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<Array<GeoA
**系统能力**:SystemCapability.Location.Location.Geocoder
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| request | [GeoCodeRequest](#geocoderequest) | 是 | 设置地理编码请求的相关参数。 |
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<Array<[GeoAddress](#geoaddress)>> | 设置接收地理编码请求的回调参数。 |
-- 示例:
+**示例**
- ```
+ ```js
var geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
@@ -909,7 +982,6 @@ getAddressesFromLocationName(request: GeoCodeRequest) : Promise<Array<GeoA
```
-
## geolocation.getCachedGnssLocationsSize8+
getCachedGnssLocationsSize(callback: AsyncCallback<number>) : void;
@@ -920,16 +992,22 @@ getCachedGnssLocationsSize(callback: AsyncCallback<number>) : void;
**系统能力**:SystemCapability.Location.Location.Gnss
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<number> | 是 | 用来接收GNSS芯片缓存位置个数的回调。 |
-- 示例:
+**示例**
- ```
+ ```js
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<number>;
**系统能力**:SystemCapability.Location.Location.Gnss
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<number> | 返回GNSS缓存位置的个数。 |
-- 示例:
+**示例**
- ```
+ ```js
geolocation.getCachedGnssLocationsSize().then((result) => {
- console.log('promise, getCachedGnssLocationsSize: ' + result);
+ console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
});
```
@@ -968,16 +1047,22 @@ flushCachedGnssLocations(callback: AsyncCallback<boolean>) : void;
**系统能力**:SystemCapability.Location.Location.Gnss
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback<boolean> | 是 | 用来接收清空GNSS芯片缓存位置操作的结果。 |
-- 示例:
+**示例**
- ```
+ ```js
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<boolean>;
**系统能力**:SystemCapability.Location.Location.Gnss
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<boolean> | 清空所有GNSS缓存位置是否成功。 |
-- 示例:
+**示例**
- ```
+ ```js
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<boolean>) :
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| command | LocationCommand | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
| callback | AsyncCallback<boolean> | 是 | 用来接收命令发送的结果。 |
-- 示例:
+**示例**
- ```
+ ```js
var requestInfo = {'scenario': 0x301, 'command': "command_1"};
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<boolean>;
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| command | LocationCommand | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<boolean> | 表示命令发送成功或失败。 |
-- 示例:
+**示例**
- ```
+ ```js
var requestInfo = {'scenario': 0x301, 'command': "command_1"};
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
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| callback | AsyncCallback<boolean> | 是 | 表示用户是否同意定位服务隐私申明。 |
-- 示例:
+**示例**
- ```
+ ```js
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<boolean>
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<boolean> | 表示用户是否同意定位服务隐私申明。 |
-- 示例:
+**示例**
- ```
+ ```js
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
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 |
| callback | AsyncCallback<boolean> | 是 | 表示操作是否成功。 |
-- 示例:
+**示例**
- ```
+ ```js
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
**系统能力**:SystemCapability.Location.Location.Core
-- 参数:
+**参数**:
+
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 |
-- 返回值:
+**返回值**:
+
| 参数名 | 说明 |
| -------- | -------- |
| Promise<boolean> | 表示操作是否成功。 |
-- 示例:
+**示例**
- ```
+ ```js
geolocation.setLocationPrivacyConfirmStatus(1, true).then((result) => {
- console.log('promise, setLocationPrivacyConfirmStatus: ' + result);
+ console.log('promise, setLocationPrivacyConfirmStatus: ' + JSON.stringify(result));
+ });
+ ```
+
+
+## geolocation.getCountryCode9+
+
+getCountryCode(callback: AsyncCallback<CountryCode>) : void;
+
+查询当前的国家码。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | callback | AsyncCallback<CountryCode> | 是 | 用来接收国家码。 |
+
+**示例**
+
+ ```js
+ geolocation.getCountryCode((err, result) => {
+ if (err) {
+ console.log('getCountryCode: err=' + JSON.stringify(err));
+ }
+ if (result) {
+ console.log('getCountryCode: result=' + JSON.stringify(result));
+ }
+ });
+ ```
+
+
+## geolocation.getCountryCode9+
+
+getCountryCode() : Promise<CountryCode>;
+
+查询当前的国家码。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**参数**:
+
+无
+
+**返回值**:
+
+ | 参数名 | 说明 |
+ | -------- | -------- |
+ | Promise<CountryCode> | 返回国家码。 |
+
+**示例**
+
+ ```js
+ geolocation.getCountryCode()
+ .then((result) => {
+ console.log('promise, getCountryCode: result=' + JSON.stringify(result));
+ })
+ .catch((error) => {
+ console.log('promise, getCountryCode: error=' + JSON.stringify(error));
+ });
+ ```
+
+
+## geolocation.enableLocationMock9+
+
+enableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback<void>) : void;
+
+使能某个场景的位置模拟功能,同一时间只能使能一个场景的位置模拟功能。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | scenario | LocationRequestScenario | 否 | 指示在什么场景下使能位置模拟功能。 |
+ | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回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.enableLocationMock9+
+
+enableLocationMock(scenario?: LocationRequestScenario) : Promise<void>;
+
+使能某个场景的位置模拟功能,同一时间只能使能一个场景的位置模拟功能。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | scenario | LocationRequestScenario | 否 | 指示使能什么场景的位置模拟功能。如果不携带该参数则表示使能所有场景的位置模拟功能。 |
+
+
+**返回值**:
+
+ | 参数名 | 说明 |
+ | -------- | -------- |
+ | Promise<void> | 用来接收执行结果,如果执行成功就返回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.disableLocationMock9+
+
+disableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback<void>) : void;
+
+去使能位置模拟功能。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | scenario | LocationRequestScenario | 否 | 指示去使能某个场景的位置模拟功能。如果不携带该参数则表示去使能所有场景的位置模拟功能。 |
+ | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回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.disableLocationMock9+
+
+disableLocationMock(scenario?: LocationRequestScenario) : Promise<void>;
+
+去使能位置模拟功能。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | scenario | LocationRequestScenario | 否 | 指示去使能某个场景的位置模拟功能。如果不携带该参数则表示去使能所有场景的位置模拟功能。 |
+
+**返回值**:
+
+ | 参数名 | 说明 |
+ | -------- | -------- |
+ | Promise<void> | 用来接收执行结果,如果执行成功就返回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.setMockedLocations9+
+
+setMockedLocations(config: LocationMockConfig, callback: AsyncCallback<void>) : void;
+
+设置模拟的位置信息,后面会以该接口中携带的时间间隔上报模拟位置。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | config | LocationMockConfig | 是 | 指示位置模拟的配置参数,包含模拟位置上报的时间间隔和模拟位置数组。 |
+ | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回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.setMockedLocations9+
+
+setMockedLocations(config: LocationMockConfig) : Promise<void>;
+
+设置模拟的位置信息,后面会以该接口中携带的时间间隔上报模拟位置。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | config | LocationMockConfig | 是 | 指示位置模拟的配置参数,包含模拟位置上报的时间间隔和模拟位置数组。 |
+
+**返回值**:
+
+ | 参数名 | 说明 |
+ | -------- | -------- |
+ | Promise<void> | 用来接收执行结果,如果执行成功就返回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.enableReverseGeocodingMock9+
+
+enableReverseGeocodingMock(callback: AsyncCallback<void>) : void;
+
+使能逆地理编码模拟功能。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回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.enableReverseGeocodingMock9+
+
+enableReverseGeocodingMock() : Promise<void>;
+
+使能逆地理编码模拟功能。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+无
+
+**返回值**:
+
+ | 参数名 | 说明 |
+ | -------- | -------- |
+ | Promise<void> | 用来接收执行结果,如果执行成功就返回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.disableReverseGeocodingMock9+
+
+disableReverseGeocodingMock(callback: AsyncCallback<void>) : void;
+
+去使能逆地理编码模拟功能。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回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.disableReverseGeocodingMock9+
+
+disableReverseGeocodingMock() : Promise<void>;
+
+去使能逆地理编码模拟功能。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+无
+
+**返回值**:
+
+ | 参数名 | 说明 |
+ | -------- | -------- |
+ | Promise<void> | 用来接收执行结果,如果执行成功就返回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.setReverseGeocodingMockInfo9+
+
+setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>, callback: AsyncCallback<void>) : void;
+
+设置逆地理编码模拟功能的配置信息,包含了位置和地名的对应关系,后续进行逆地理编码查询时如果位置信息位于配置信息中,就返回对应的地名。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | mockInfos | Array<ReverseGeocodingMockInfo> | 是 | 指示逆地理编码模拟功能的配置参数数组。逆地理编码模拟功能的配置参数包含了一个位置和一个地名。 |
+ | callback | AsyncCallback<void> | 是 | 用来接收执行结果,如果执行成功就返回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.setReverseGeocodingMockInfo9+
+
+setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>) : Promise<void>;
+
+设置逆地理编码模拟功能的配置信息,包含了位置和地名的对应关系,后续进行逆地理编码查询时如果位置信息位于配置信息中,就返回对应的地名。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+**参数**:
+
+ | 参数名 | 类型 | 必填 | 说明 |
+ | -------- | -------- | -------- | -------- |
+ | mockInfos | Array<ReverseGeocodingMockInfo> | 是 | 指示逆地理编码模拟功能的配置信息数组。逆地理编码模拟功能的配置信息包含了一个位置和一个地名。 |
+
+**返回值**:
+
+ | 参数名 | 说明 |
+ | -------- | -------- |
+ | Promise<void> | 用来接收执行结果,如果执行成功就返回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
@@ -1225,13 +1841,15 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolea
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
-| INPUT_PARAMS_ERROR | 101 | 表示输入参数错误。 |
-| REVERSE_GEOCODE_ERROR | 102 | 表示逆地理编码接口调用失败。 |
-| GEOCODE_ERROR | 103 | 表示地理编码接口调用失败。 |
-| LOCATOR_ERROR | 104 | 表示定位失败。 |
-| LOCATION_SWITCH_ERROR | 105 | 表示定位开关。 |
-| LAST_KNOWN_LOCATION_ERROR | 106 | 表示获取上次位置失败。 |
-| LOCATION_REQUEST_TIMEOUT_ERROR | 107 | 表示单次定位,没有在指定时间内返回位置。 |
+| NOT_SUPPORTED9+ | 100 | 表示该接口功能不支持。 |
+| INPUT_PARAMS_ERROR7+ | 101 | 表示输入参数错误。 |
+| REVERSE_GEOCODE_ERROR7+ | 102 | 表示逆地理编码接口调用失败。 |
+| GEOCODE_ERROR7+ | 103 | 表示地理编码接口调用失败。 |
+| LOCATOR_ERROR7+ | 104 | 表示定位失败。 |
+| LOCATION_SWITCH_ERROR7+ | 105 | 表示定位开关。 |
+| LAST_KNOWN_LOCATION_ERROR7+ | 106 | 表示获取上次位置失败。 |
+| LOCATION_REQUEST_TIMEOUT_ERROR7+ | 107 | 表示单次定位,没有在指定时间内返回位置。 |
+| QUERY_COUNTRY_CODE_ERROR9+ | 108 | 表示国家码查询失败。 |
## ReverseGeoCodeRequest
@@ -1279,24 +1897,25 @@ setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolea
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
-| latitude | number | 否 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
-| longitude | number | 否 | 表示经度信息,正值表示东经,负值表是西经。 |
-| locale | string | 否 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
-| placeName | string | 否 | 表示地区信息。 |
-| countryCode | string | 否 | 表示国家码信息。 |
-| countryName | string | 否 | 表示国家信息。 |
-| administrativeArea | string | 否 | 表示省份区域信息。 |
-| subAdministrativeArea | string | 否 | 表示表示子区域信息。 |
-| locality | string | 否 | 表示城市信息。 |
-| subLocality | string | 否 | 表示子城市信息。 |
-| roadName | string | 否 | 表示路名信息。 |
-| subRoadName | string | 否 | 表示子路名信息。 |
-| premises | string | 否 | 表示门牌号信息。 |
-| postalCode | string | 否 | 表示邮政编码信息。 |
-| phoneNumber | string | 否 | 表示联系方式信息。 |
-| addressUrl | string | 否 | 表示位置信息附件的网址信息。 |
-| descriptions | Array<string> | 否 | 表示附加的描述信息。 |
-| descriptionsSize | number | 否 | 表示附加的描述信息数量。 |
+| latitude7+ | number | 否 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
+| longitude7+ | number | 否 | 表示经度信息,正值表示东经,负值表是西经。 |
+| locale7+ | string | 否 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
+| placeName7+ | string | 否 | 表示地区信息。 |
+| countryCode7+ | string | 否 | 表示国家码信息。 |
+| countryName7+ | string | 否 | 表示国家信息。 |
+| administrativeArea7+ | string | 否 | 表示省份区域信息。 |
+| subAdministrativeArea7+ | string | 否 | 表示表示子区域信息。 |
+| locality7+ | string | 否 | 表示城市信息。 |
+| subLocality7+ | string | 否 | 表示子城市信息。 |
+| roadName7+ | string | 否 | 表示路名信息。 |
+| subRoadName7+ | string | 否 | 表示子路名信息。 |
+| premises7+ | string | 否 | 表示门牌号信息。 |
+| postalCode7+ | string | 否 | 表示邮政编码信息。 |
+| phoneNumber7+ | string | 否 | 表示联系方式信息。 |
+| addressUrl7+ | string | 否 | 表示位置信息附件的网址信息。 |
+| descriptions7+ | Array<string> | 否 | 表示附加的描述信息。 |
+| descriptionsSize7+ | number | 否 | 表示附加的描述信息数量。 |
+| isFromMock9+ | Boolean | 否 | 表示地名信息是否来自于逆地理编码模拟功能。 |
## LocationRequest
@@ -1434,13 +2053,68 @@ GNSS围栏的配置参数。目前只支持圆形围栏。
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
-| latitude | number | 是 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
-| longitude | number | 是 | 表示经度信息,正值表示东经,负值表是西经。 |
-| altitude | number | 是 | 表示高度信息,单位米。 |
-| accuracy | number | 是 | 表示精度信息,单位米。 |
-| speed | number | 是 | 表示速度信息,单位米每秒。 |
-| timeStamp | number | 是 | 表示位置时间戳,UTC格式。 |
-| direction | number | 是 | 表示航向信息。 |
-| timeSinceBoot | number | 是 | 表示位置时间戳,开机时间格式。 |
-| additions | Array<string> | 否 | 附加信息。 |
-| additionSize | number | 否 | 附加信息数量。 |
+| latitude7+ | number | 是 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
+| longitude7+ | number | 是 | 表示经度信息,正值表示东经,负值表是西经。 |
+| altitude7+ | number | 是 | 表示高度信息,单位米。 |
+| accuracy7+ | number | 是 | 表示精度信息,单位米。 |
+| speed7+ | number | 是 | 表示速度信息,单位米每秒。 |
+| timeStamp7+ | number | 是 | 表示位置时间戳,UTC格式。 |
+| direction7+ | number | 是 | 表示航向信息。 |
+| timeSinceBoot7+ | number | 是 | 表示位置时间戳,开机时间格式。 |
+| additions7+ | Array<string> | 否 | 附加信息。 |
+| additionSize7+ | number | 否 | 附加信息数量。 |
+| isFromMock9+ | Boolean | 否 | 表示位置信息是否来自于位置模拟功能。 |
+
+
+## ReverseGeocodingMockInfo9+
+
+逆地理编码模拟功能的配置信息,包含一个位置信息和一个地名信息。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+| 名称 | 参数类型 | 必填 | 说明 |
+| -------- | -------- | -------- | -------- |
+| location | ReverseGeoCodeRequest | 是 | 表示经纬度信息。 |
+| geoAddress | GeoAddress | 是 | 表示地名信息。 |
+
+
+## LocationMockConfig9+
+
+位置模拟功能的配置参数,包含了模拟位置上报的时间间隔和模拟位置数组。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+**系统API**:此接口为系统接口,三方应用不支持调用。
+
+| 名称 | 参数类型 | 必填 | 说明 |
+| -------- | -------- | -------- | -------- |
+| timeInterval | number | 是 | 表示模拟位置上报的时间间隔,单位是秒。 |
+| locations | Array<Location> | 是 | 表示模拟位置数组。 |
+
+
+## CountryCode9+
+
+国家码信息结构体,包含国家码字符串和国家码的来源信息。
+
+**系统能力**:SystemCapability.Location.Location.Core
+
+| 名称 | 参数类型 | 必填 | 说明 |
+| -------- | -------- | -------- | -------- |
+| country | string | 是 | 表示国家码字符串。 |
+| type | CountryCodeType | 是 | 表示国家码信息来源。 |
+
+
+## CountryCodeType9+
+
+国家码来源类型。
+
+**系统能力**: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