提交 d1157ec1 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 8beeb946
...@@ -23,12 +23,12 @@ If your application needs to access the device location information, it must fir ...@@ -23,12 +23,12 @@ If your application needs to access the device location information, it must fir
- API version 9 and later: Apply for **ohos.permission.APPROXIMATELY\_LOCATION**, or apply for **ohos.permission.APPROXIMATELY\_LOCATION** and **ohos.permission.LOCATION**. Note that **ohos.permission.LOCATION** cannot be applied for separately. - API version 9 and later: Apply for **ohos.permission.APPROXIMATELY\_LOCATION**, or apply for **ohos.permission.APPROXIMATELY\_LOCATION** and **ohos.permission.LOCATION**. Note that **ohos.permission.LOCATION** cannot be applied for separately.
| API Version| Location Permission | Permission Application Result| Location Accuracy | | API Version| Location Permission| Permission Application Result| Location Accuracy|
| ------------- | ------------------------------------------------------------ | -------- | -------------------------------- | | -------- | -------- | -------- | -------- |
| Earlier than 9 | ohos.permission.LOCATION | Success | Location accurate to meters| | Earlier than 9| ohos.permission.LOCATION | Success| Location accurate to meters|
| 9 and later | ohos.permission.LOCATION | Failure | No location obtained | | 9 and later| ohos.permission.LOCATION | Failure| No location obtained|
| 9 and later | ohos.permission.APPROXIMATELY_LOCATION | Success | Location accurate to 5 kilometers | | 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers|
| 9 and later | ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success | Location accurate to meters| | 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters|
If your application needs to access the device location information when running in the background, it must be configured to be able to run in the background and be granted the **ohos.permission.LOCATION_IN_BACKGROUND** permission. In this way, the system continues to report device location information after your application moves to the background. If your application needs to access the device location information when running in the background, it must be configured to be able to run in the background and be granted the **ohos.permission.LOCATION_IN_BACKGROUND** permission. In this way, the system continues to report device location information after your application moves to the background.
...@@ -42,31 +42,615 @@ import geoLocationManager from '@ohos.geoLocationManager'; ...@@ -42,31 +42,615 @@ import geoLocationManager from '@ohos.geoLocationManager';
``` ```
## geoLocationManager.on('locationChange')
on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Location&gt;): void
Registers a listener for location changes with a location request initiated. The location result is reported through [LocationRequest](#locationrequest).
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
| request | [LocationRequest](#locationrequest) | Yes| Location request.|
| callback | Callback&lt;[Location](#location)&gt; | Yes| Callback used to return the location change event.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301200 | Failed to obtain the geographical location. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
};
try {
geoLocationManager.on('locationChange', requestInfo, locationChange);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.off('locationChange')
off(type: 'locationChange', callback?: Callback&lt;Location&gt;): void
Unregisters the listener for location changes with the corresponding location request deleted.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
| callback | Callback&lt;[Location](#location)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301200 | Failed to obtain the geographical location. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
};
try {
geoLocationManager.on('locationChange', requestInfo, locationChange);
geoLocationManager.off('locationChange', locationChange);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.on('locationEnabledChange')
on(type: 'locationEnabledChange', callback: Callback&lt;boolean&gt;): void
Registers a listener for location service status change events.
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change event.|
| callback | Callback&lt;boolean&gt; | Yes| Callback used to return the location service status change event.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var locationEnabledChange = (state) => {
console.log('locationEnabledChange: ' + JSON.stringify(state));
}
try {
geoLocationManager.on('locationEnabledChange', locationEnabledChange);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.off('locationEnabledChange')
off(type: 'locationEnabledChange', callback?: Callback&lt;boolean&gt;): void;
Unregisters the listener for location service status change events.
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **locationEnabledChange** indicates a location service status change event.|
| callback | Callback&lt;boolean&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var locationEnabledChange = (state) => {
console.log('locationEnabledChange: state: ' + JSON.stringify(state));
}
try {
geoLocationManager.on('locationEnabledChange', locationEnabledChange);
geoLocationManager.off('locationEnabledChange', locationEnabledChange);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.on('cachedGnssLocationsChange')
on(type: 'cachedGnssLocationsChange', request: CachedGnssLocationsRequest, callback: Callback&lt;Array&lt;Location&gt;&gt;): void;
Registers a listener for cached GNSS location reports.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Gnss
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.|
| request | [CachedGnssLocationsRequest](#cachedgnsslocationsrequest) | Yes| Request for reporting cached GNSS location.|
| callback | Callback&lt;boolean&gt; | Yes| Callback used to return cached GNSS locations.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301200 | Failed to obtain the geographical location. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var cachedLocationsCb = (locations) => {
console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
}
var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
try {
geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.off('cachedGnssLocationsChange')
off(type: 'cachedGnssLocationsChange', callback?: Callback&lt;Array&lt;Location&gt;&gt;): void;
Unregisters the listener for cached GNSS location reports.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Gnss
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **cachedGnssLocationsChange** indicates reporting of cached GNSS locations.|
| callback | Callback&lt;boolean&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301200 | Failed to obtain the geographical location. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var cachedLocationsCb = (locations) => {
console.log('cachedGnssLocationsChange: locations: ' + JSON.stringify(locations));
}
var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
try {
geoLocationManager.on('cachedGnssLocationsChange', requestInfo, cachedLocationsCb);
geoLocationManager.off('cachedGnssLocationsChange');
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.on('satelliteStatusChange')
on(type: 'satelliteStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;): void;
Registers a listener for GNSS satellite status change events.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Gnss
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change event.|
| callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | Yes| Callback used to return GNSS satellite status changes.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var gnssStatusCb = (satelliteStatusInfo) => {
console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
try {
geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.off('satelliteStatusChange')
off(type: 'satelliteStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;): void;
Unregisters the listener for GNSS satellite status change events.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Gnss
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **satelliteStatusChange** indicates a GNSS satellite status change event.|
| callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var gnssStatusCb = (satelliteStatusInfo) => {
console.log('satelliteStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
try {
geoLocationManager.on('satelliteStatusChange', gnssStatusCb);
geoLocationManager.off('satelliteStatusChange', gnssStatusCb);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.on('nmeaMessage')
on(type: 'nmeaMessage', callback: Callback&lt;string&gt;): void;
Registers a listener for GNSS NMEA message change events.
**Permission required**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Gnss
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change event.|
| callback | Callback&lt;string&gt; | Yes| Callback used to return GNSS NMEA message changes.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var nmeaCb = (str) => {
console.log('nmeaMessage: ' + JSON.stringify(str));
}
try {
geoLocationManager.on('nmeaMessage', nmeaCb );
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.off('nmeaMessage')
off(type: 'nmeaMessage', callback?: Callback&lt;string&gt;): void;
Unregisters the listener for GNSS NMEA message change events.
**Permission required**: ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Gnss
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **nmeaMessage** indicates a GNSS NMEA message change event.|
| callback | Callback&lt;string&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var nmeaCb = (str) => {
console.log('nmeaMessage: ' + JSON.stringify(str));
}
try {
geoLocationManager.on('nmeaMessage', nmeaCb);
geoLocationManager.off('nmeaMessage', nmeaCb);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.on('gnssFenceStatusChange')
on(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
Registers a listener for status change events of the specified geofence.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Geofence
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change event.|
| request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
| want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301600 | Failed to operate the geofence. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
import wantAgent from '@ohos.wantAgent';
let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
action: "action1",
}
],
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
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}};
try {
geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
});
```
## geoLocationManager.off('gnssFenceStatusChange')
off(type: 'gnssFenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
Unregisters the listener for status change events of the specified geofence.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Geofence
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **gnssFenceStatusChange** indicates a geofence status change event.|
| request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
| want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301600 | Failed to operate the geofence. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
import wantAgent from '@ohos.wantAgent';
let wantAgentInfo = {
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility",
action: "action1",
}
],
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
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}};
try {
geoLocationManager.on('gnssFenceStatusChange', requestInfo, wantAgentObj);
geoLocationManager.off('gnssFenceStatusChange', requestInfo, wantAgentObj);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
});
```
## geoLocationManager.on('countryCodeChange') ## geoLocationManager.on('countryCodeChange')
on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;): void; on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;): void;
Registers a listener for country code change events.
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change event.|
| callback | Callback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to return the country code change event.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301500 | Failed to query the area information. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var callback = (code) => {
console.log('countryCodeChange: ' + JSON.stringify(code));
}
try {
geoLocationManager.on('countryCodeChange', callback);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.off('countryCodeChange')
off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;): void;
Subscribes to the country code change event. Unregisters the listener for country code change events.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| type | string | Yes | Event type. The value **countryCodeChange** indicates to subscribe to the country code change event.| | type | string | Yes| Event type. The value **countryCodeChange** indicates a country code change event.|
| callback | Callback&lt;[CountryCode](#countrycode)&gt; | Yes | Callback used to return the country code change event. | | callback | Callback&lt;[CountryCode](#countrycode)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message |
| -------- | ------------------------------------- |
| 3301000 | Location service is unavailable. |
| 3301100 | The location switch is off. |
| 3301500 | Failed to query the area information. |
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301500 | Failed to query the area information. |
**Example** **Example**
...@@ -78,47 +662,310 @@ For details about the following error codes, see [error codes of the location se ...@@ -78,47 +662,310 @@ For details about the following error codes, see [error codes of the location se
try { try {
geoLocationManager.on('countryCodeChange', callback); geoLocationManager.on('countryCodeChange', callback);
geoLocationManager.off('countryCodeChange', callback);
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
} }
``` ```
## geoLocationManager.off('countryCodeChange')
off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;): void; ## geoLocationManager.getCurrentLocation
Unsubscribes from the country code change event. getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;Location&gt;): void
Obtains the current location. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| type | string | Yes | Event type. The value **countryCodeChange** indicates to unsubscribe from the country code change event.| | request | [CurrentLocationRequest](#currentlocationrequest) | Yes| Location request.|
| callback | Callback&lt;[CountryCode](#countrycode)&gt; | No | Callback used for unsubscription. If this parameter is not specified, all callbacks of the specified event type are unsubscribed from.| | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the current location.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | ------------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
| 3301100 | The location switch is off. | |3301100 | The location switch is off. |
| 3301500 | Failed to query the area information. | |3301200 | Failed to obtain the geographical location. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
var callback = (code) => { var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
console.log('countryCodeChange: ' + JSON.stringify(code)); var locationChange = (err, location) => {
if (err) {
console.log('locationChanger: err=' + JSON.stringify(err));
}
if (location) {
console.log('locationChanger: location=' + JSON.stringify(location));
} }
};
try { try {
geoLocationManager.on('countryCodeChange', callback); geoLocationManager.getCurrentLocation(requestInfo, locationChange);
geoLocationManager.off('countryCodeChange', callback); } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.getCurrentLocation
getCurrentLocation(callback: AsyncCallback&lt;Location&gt;): void;
Obtains the current location. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the current location.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301200 | Failed to obtain the geographical location. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var locationChange = (err, location) => {
if (err) {
console.log('locationChanger: err=' + JSON.stringify(err));
}
if (location) {
console.log('locationChanger: location=' + JSON.stringify(location));
}
};
try {
geoLocationManager.getCurrentLocation(locationChange);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.getCurrentLocation
getCurrentLocation(request?: CurrentLocationRequest): Promise&lt;Location&gt;
Obtains the current location. This API uses a promise to return the result.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.|
**Return value**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Promise&lt;[Location](#location)&gt; | [Location](#location) | NA | Promise used to return the current location.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301200 | Failed to obtain the geographical location. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
try {
geoLocationManager.getCurrentLocation(requestInfo).then((result) => {
console.log('current location: ' + JSON.stringify(result));
})
.catch((error) => {
console.log('promise, getCurrentLocation: error=' + JSON.stringify(error));
});
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.getLastLocation
getLastLocation(): Location
Obtains the last location.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core
**Return value**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Location | [Location](#location) | NA | Location information.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301200 |Failed to obtain the geographical location. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
try {
var location = geoLocationManager.getLastLocation();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.isLocationEnabled
isLocationEnabled(): boolean
Checks whether the location service is enabled.
**System capability**: SystemCapability.Location.Location.Core
**Return value**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| boolean | boolean | NA | Result indicating whether the location service is enabled.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
try {
var locationEnabled = geoLocationManager.isLocationEnabled();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.requestEnableLocation
requestEnableLocation(callback: AsyncCallback&lt;boolean&gt;): void
Requests to enable the location service. This API uses an asynchronous callback to return the result.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. The value **true** indicates that the user agrees to enable the location service, and the value **false** indicates the opposite.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301700 | No response to the request. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
try {
geoLocationManager.requestEnableLocation((err, data) => {
if (err) {
console.log('requestEnableLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('requestEnableLocation: data=' + JSON.stringify(data));
}
});
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.requestEnableLocation
requestEnableLocation(): Promise&lt;boolean&gt;
Requests to enable the location service. This API uses a promise to return the result.
**Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core
**Return value**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| Promise&lt;boolean&gt; | boolean | NA | Promise used to return the result. The value **true** indicates that the user agrees to enable the location service, and the value **false** indicates the opposite.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301700 | No response to the request. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
try {
geoLocationManager.requestEnableLocation().then((result) => {
console.log('promise, requestEnableLocation: ' + JSON.stringify(result));
})
.catch((error) => {
console.log('promise, requestEnableLocation: error=' + JSON.stringify(error));
});
} catch (err) { } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message); console.error("errCode:" + err.code + ",errMessage:" + err.message);
} }
...@@ -139,27 +986,31 @@ Enables the location service. This API uses an asynchronous callback to return t ...@@ -139,27 +986,31 @@ Enables the location service. This API uses an asynchronous callback to return t
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| -------- | ------------------------- | ---- | -------------------- | | -------- | -------- | -------- | -------- |
| callback| AsyncCallback&lt;void&gt; | Yes | Callback used to return the error message.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the error message.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
try {
geoLocationManager.enableLocation((err, data) => { geoLocationManager.enableLocation((err, data) => {
if (err) { if (err) {
console.log('enableLocation: err=' + JSON.stringify(err)); console.log('enableLocation: err=' + JSON.stringify(err));
} }
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
...@@ -177,35 +1028,39 @@ Enables the location service. This API uses a promise to return the result. ...@@ -177,35 +1028,39 @@ Enables the location service. This API uses a promise to return the result.
**Return value** **Return value**
| Name | Type| Mandatory| Description | | Name| Type| Mandatory| Description|
| ------------------- | ---- | ---- | ---------------- | | -------- | -------- | -------- | -------- |
| Promise&lt;void&gt; | void | No | Promise used to return the error message.| | Promise&lt;void&gt; | void | NA | Promise used to return the error message.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
try {
geoLocationManager.enableLocation().then((result) => { geoLocationManager.enableLocation().then((result) => {
console.log('promise, enableLocation succeed'); console.log('promise, enableLocation succeed');
}) })
.catch((error) => { .catch((error) => {
console.log('promise, enableLocation: error=' + JSON.stringify(error)); console.log('promise, enableLocation: error=' + JSON.stringify(error));
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.disableLocation ## geoLocationManager.disableLocation
disableLocation(callback: AsyncCallback&lt;void&gt;): void; disableLocation(): void;
Disables the location service. This function uses an asynchronous callback to return the result. Disables the location service.
**System API**: 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.
...@@ -213,28 +1068,63 @@ Disables the location service. This function uses an asynchronous callback to re ...@@ -213,28 +1068,63 @@ Disables the location service. This function uses an asynchronous callback to re
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
try {
geoLocationManager.disableLocation();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.getAddressesFromLocation
getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
Converts coordinates into geographic description through reverse geocoding. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Location.Location.Geocoder
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| -------- | ------------------------- | ---- | ---------------------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the error code.| | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
| callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the reverse geocoding result.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
|3301300 | Reverse geocoding query failed. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
try { try {
geoLocationManager.disableLocation((err, data) => { geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
if (err) { if (err) {
console.log('disableLocation: err=' + JSON.stringify(err)); console.log('getAddressesFromLocation: err=' + JSON.stringify(err));
}
if (data) {
console.log('getAddressesFromLocation: data=' + JSON.stringify(data));
} }
}); });
} catch (err) { } catch (err) {
...@@ -243,546 +1133,584 @@ For details about the following error codes, see [error codes of the location se ...@@ -243,546 +1133,584 @@ For details about the following error codes, see [error codes of the location se
``` ```
## geoLocationManager.disableLocation ## geoLocationManager.getAddressesFromLocation
disableLocation(): Promise&lt;void&gt; getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;;
Disables the location service. This function uses a promise to return the result. Converts coordinates into geographic description through reverse geocoding. This API uses a promise to return the result.
**System API**: This is a system API and cannot be called by third-party applications. **System capability**: SystemCapability.Location.Location.Geocoder
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Parameters**
**System capability**: SystemCapability.Location.Location.Core | Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
**Return value** **Return value**
| Name | Type| Mandatory| Description | | Name| Type| Mandatory| Description|
| ------------------- | ---- | ---- | ------------ | | -------- | -------- | -------- | -------- |
| Promise&lt;void&gt; | void | No | Promise used to return the error code.| | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Array&lt;[GeoAddress](#geoaddress)&gt; | NA | Promise used to return the reverse geocoding result.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
|3301300 | Reverse geocoding query failed. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.disableLocation().then((result) => { var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
console.log('promise, disableLocation succeed'); try {
geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
console.log('getAddressesFromLocation: ' + JSON.stringify(data));
}) })
.catch((error) => { .catch((error) => {
console.log('promise, disableLocation: error=' + JSON.stringify(error)); console.log('promise, getAddressesFromLocation: error=' + JSON.stringify(error));
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.isLocationPrivacyConfirmed ## geoLocationManager.getAddressesFromLocationName
isLocationPrivacyConfirmed(type : LocationPrivacyType, callback: AsyncCallback&lt;boolean&gt;): void;
Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications. getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
**System API**: This is a system API and cannot be called by third-party applications. Converts geographic description into coordinates through geocoding. This API uses an asynchronous callback to return the result.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Geocoder
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| -------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| type | [LocationPrivacyType](#locationprivacytype) | Yes | Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when the location service is enabled. | | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
| callback | AsyncCallback&lt;boolean&gt; | Yes | Callback used to return the result, which indicates whether the user agrees with the privacy statement. | | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the geocoding result.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
|3301400 | Geocoding query failed. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.isLocationPrivacyConfirmed(1, (err, result) => { var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
try {
geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => {
if (err) { if (err) {
console.log('isLocationPrivacyConfirmed: err=' + JSON.stringify(err)); console.log('getAddressesFromLocationName: err=' + JSON.stringify(err));
} }
if (result) { if (data) {
console.log('isLocationPrivacyConfirmed: result=' + JSON.stringify(result)); console.log('getAddressesFromLocationName: data=' + JSON.stringify(data));
} }
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.isLocationPrivacyConfirmed ## geoLocationManager.getAddressesFromLocationName
isLocationPrivacyConfirmed(type : LocationPrivacyType,): Promise&lt;boolean&gt;;
Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications. getAddressesFromLocationName(request: GeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;
**System API**: This is a system API and cannot be called by third-party applications. Converts geographic description into coordinates through geocoding. This API uses a promise to return the result.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Geocoder
**Parameters** **Parameters**
| Name| Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| ------ | ------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| type | [LocationPrivacyType](#locationprivacytype) | Yes | Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when the location service is enabled. | | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
**Return value** **Return value**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| ---------------------- | ------- | ---- | ---------------------------------- | | -------- | -------- | -------- | -------- |
| Promise&lt;boolean&gt; | boolean | No | Callback used to return the result, which indicates whether the user agrees with the privacy statement.| | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Array&lt;[GeoAddress](#geoaddress)&gt; | NA | Promise used to return the geocoding result.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
|3301400 | Geocoding query failed. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.isLocationPrivacyConfirmed(1).then((result) => { var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
console.log('promise, isLocationPrivacyConfirmed: ' + JSON.stringify(result)); try {
geoLocationManager.getAddressesFromLocationName(geocodeRequest).then((result) => {
console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
})
.catch((error) => {
console.log('promise, getAddressesFromLocationName: error=' + JSON.stringify(error));
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
```
## geoLocationManager.isGeocoderAvailable
isGeocoderAvailable(): boolean;
Obtains the (reverse) geocoding service status.
**System capability**: SystemCapability.Location.Location.Geocoder
**Return value**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| boolean | boolean | NA | Result indicating whether the (reverse) geocoding service is available.|
**Error codes**
For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**Example**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
try {
var isAvailable = geoLocationManager.isGeocoderAvailable();
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.setLocationPrivacyConfirmStatus ## geoLocationManager.getCachedGnssLocationsSize
setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed: boolean, callback: AsyncCallback&lt;void&gt;): void;
Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications. getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;): void;
**System API**: This is a system API and cannot be called by third-party applications. Obtains the number of cached GNSS locations.
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS **Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Gnss
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| ----------- | ------------------------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| type | [LocationPrivacyType](#locationprivacytype) | Yes | Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when the location service is enabled. | | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of cached GNSS locations. |
| isConfirmed | boolean | Yes | Callback used to return the result, which indicates whether the user agrees with the privacy statement. |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the error message. |
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.setLocationPrivacyConfirmStatus(1, true, (err, result) => { try {
geoLocationManager.getCachedGnssLocationsSize((err, size) => {
if (err) { if (err) {
console.log('setLocationPrivacyConfirmStatus: err=' + JSON.stringify(err)); console.log('getCachedGnssLocationsSize: err=' + JSON.stringify(err));
}
if (size) {
console.log('getCachedGnssLocationsSize: size=' + JSON.stringify(size));
} }
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.setLocationPrivacyConfirmStatus ## geoLocationManager.getCachedGnssLocationsSize
setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolean): Promise&lt;void&gt;;
Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications.
**System API**: This is a system API and cannot be called by third-party applications. getCachedGnssLocationsSize(): Promise&lt;number&gt;;
**Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
**System capability**: SystemCapability.Location.Location.Core Obtains the number of cached GNSS locations.
**Parameters** **Permission required**: ohos.permission.APPROXIMATELY_LOCATION
| Name | Type | Mandatory| Description | **System capability**: SystemCapability.Location.Location.Gnss
| ----------- | ------------------------------------------- | ---- | ------------------------------------------------------------ |
| type | [LocationPrivacyType](#locationprivacytype) | Yes | Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when the location service is enabled. |
| isConfirmed | boolean | Yes | Callback used to return the result, which indicates whether the user agrees with the privacy statement. |
**Return value** **Return value**
| Name | Type| Mandatory| Description | | Name| Type| Mandatory| Description|
| ------------------- | ---- | ---- | ------------ | | -------- | -------- | -------- | -------- |
| Promise&lt;void&gt; | void | No | Promise used to return the error code.| | Promise&lt;number&gt; | number | NA | Promise used to return the number of cached GNSS locations.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.setLocationPrivacyConfirmStatus(1, true).then((result) => { try {
console.log('promise, setLocationPrivacyConfirmStatus succeed'); geoLocationManager.getCachedGnssLocationsSize().then((result) => {
console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
}) })
.catch((error) => { .catch((error) => {
console.log('promise, disableLocation: error=' + JSON.stringify(error)); console.log('promise, getCachedGnssLocationsSize: error=' + JSON.stringify(error));
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.getCountryCode ## geoLocationManager.flushCachedGnssLocations
getCountryCode(callback: AsyncCallback&lt;CountryCode&gt;): void; flushCachedGnssLocations(callback: AsyncCallback&lt;void&gt;): void;
Obtains the current country code. Obtains all cached GNSS locations and clears the GNSS cache queue.
**System capability**: SystemCapability.Location.Location.Core **Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Gnss
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| -------- | ------------------------------------------------ | ---- | ---------------- | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[CountryCode](#countrycode)&gt; | Yes | Callback used to return the country code.| | callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the error message.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | ------------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
| 3301500 | Failed to query the area information. | |3301100 | The location switch is off. |
|3301200 | Failed to obtain the geographical location. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.getCountryCode((err, result) => { try {
geoLocationManager.flushCachedGnssLocations((err, result) => {
if (err) { if (err) {
console.log('getCountryCode: err=' + JSON.stringify(err)); console.log('flushCachedGnssLocations: err=' + JSON.stringify(err));
}
if (result) {
console.log('getCountryCode: result=' + JSON.stringify(result));
} }
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.getCountryCode ## geoLocationManager.flushCachedGnssLocations
getCountryCode(): Promise&lt;CountryCode&gt;; flushCachedGnssLocations(): Promise&lt;void&gt;;
Obtains the current country code. Obtains all cached GNSS locations and clears the GNSS cache queue.
**System capability**: SystemCapability.Location.Location.Core **Permission required**: ohos.permission.APPROXIMATELY_LOCATION
**System capability**: SystemCapability.Location.Location.Gnss
**Return value** **Return value**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| ------------------------------------------ | --------------------------- | ---- | ---------------- | | -------- | -------- | -------- | -------- |
| Promise&lt;[CountryCode](#countrycode)&gt; | [CountryCode](#countrycode) | No | Promise used to return the country code.| | Promise&lt;void&gt; | void | NA | Promise used to return the error code.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | ------------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
| 3301500 | Failed to query the area information. | |3301100 | The location switch is off. |
|3301200 | Failed to obtain the geographical location. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.getCountryCode() try {
.then((result) => { geoLocationManager.flushCachedGnssLocations().then((result) => {
console.log('promise, getCountryCode: result=' + JSON.stringify(result)); console.log('promise, flushCachedGnssLocations success');
}) })
.catch((error) => { .catch((error) => {
console.log('promise, getCountryCode: error=' + JSON.stringify(error)); console.log('promise, flushCachedGnssLocations: error=' + JSON.stringify(error));
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.enableLocationMock ## geoLocationManager.sendCommand
enableLocationMock(callback: AsyncCallback&lt;void&gt;): void; sendCommand(command: LocationCommand, callback: AsyncCallback&lt;void&gt;): void;
Enables the mock location function. Sends an extended command to the location subsystem.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result indicating whether it is successful to enable the function. If so, **nullptr** is returned. Otherwise, an error message is returned.| | command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
| callback | AsyncCallback&lt;void&gt; | Yes| Callback used to return the error code.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
| 3301100 | The location switch is off. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.enableLocationMock((err, result) => { var requestInfo = {'scenario': 0x301, 'command': "command_1"};
try {
geoLocationManager.sendCommand(requestInfo, (err, result) => {
if (err) { if (err) {
console.log('enableLocationMock: err=' + JSON.stringify(err)); console.log('sendCommand: err=' + JSON.stringify(err));
} }
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.enableLocationMock
enableLocationMock(): Promise&lt;void&gt;; ## geoLocationManager.sendCommand
Enables the mock location function sendCommand(command: LocationCommand): Promise&lt;void&gt;;
Sends an extended command to the location subsystem.
**System capability**: SystemCapability.Location.Location.Core **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|
| -------- | -------- | -------- | -------- |
| command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
**Return value** **Return value**
| Name | Type| Mandatory| Description | | Name| Type| Mandatory| Description|
| ------------------- | ---- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| Promise&lt;void&gt; | void | No | Promise used to return the result indicating whether it is successful to enable the function. If so, **nullptr** is returned; an error message otherwise.| | Promise&lt;void&gt; | void | NA | Promise used to return the error code.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
| 3301100 | The location switch is off. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.enableLocationMock() var requestInfo = {'scenario': 0x301, 'command': "command_1"};
.then((result) => { try {
console.log('promise, enableLocationMock: succeed'); geoLocationManager.sendCommand(requestInfo).then((result) => {
console.log('promise, sendCommand success');
}) })
.catch((error) => { .catch((error) => {
if (error) { console.log('promise, sendCommand: error=' + JSON.stringify(error));
console.log('promise, enableLocationMock: error=' + JSON.stringify(error));
}
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.disableLocationMock ## geoLocationManager.getCountryCode
disableLocationMock(callback: AsyncCallback&lt;void&gt;): void; getCountryCode(callback: AsyncCallback&lt;CountryCode&gt;): void;
Disables the mock location function. Obtains the current country code.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result indicating whether it is successful to disable the function. If so, **nullptr** is returned; an error message otherwise.| | callback | AsyncCallback&lt;[CountryCode](#countrycode)&gt; | Yes| Callback used to return the country code.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
| 3301100 | The location switch is off. | |3301500 | Failed to query the area information.|
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.disableLocationMock((err, result) => { try {
geoLocationManager.getCountryCode((err, result) => {
if (err) { if (err) {
console.log('disableLocationMock: err=' + JSON.stringify(err)); console.log('getCountryCode: err=' + JSON.stringify(err));
}
if (result) {
console.log('getCountryCode: result=' + JSON.stringify(result));
} }
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.disableLocationMock ## geoLocationManager.getCountryCode
disableLocationMock(): Promise&lt;void&gt;; getCountryCode(): Promise&lt;CountryCode&gt;;
Disables the mock location function. Obtains the current country code.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Return value** **Return value**
| Name | Type| Mandatory| Description | | Name| Type| Mandatory| Description|
| ------------------- | ---- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| Promise&lt;void&gt; | void | No | Promise used to return the result indicating whether it is successful to disable the function. If so, **nullptr** is returned; an error message otherwise.| | Promise&lt;[CountryCode](#countrycode)&gt; | [CountryCode](#countrycode) | NA | Promise used to return the country code.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
| 3301100 | The location switch is off. | |3301500 | Failed to query the area information.|
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.disableLocationMock() try {
geoLocationManager.getCountryCode()
.then((result) => { .then((result) => {
console.log('promise, disableLocationMock succeed'); console.log('promise, getCountryCode: result=' + JSON.stringify(result));
}) })
.catch((error) => { .catch((error) => {
if (error) { console.log('promise, getCountryCode: error=' + JSON.stringify(error));
console.log('promise, disableLocationMock: error=' + JSON.stringify(error));
}
}); });
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
}
``` ```
## geoLocationManager.setMockedLocations ## geoLocationManager.enableLocationMock
setMockedLocations(config: LocationMockConfig, callback: AsyncCallback&lt;void&gt;): void; enableLocationMock(): void;
Sets the mock location information. The mock locations will be reported at the interval specified in this API. Enables the mock location function.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
**System API**: 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.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| config | [LocationMockConfig](#locationmockconfig) | Yes | Mock location information, including the interval for reporting the mock locations and the array of the mock locations.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result indicating whether it is successful to set the information. If so, **nullptr** is returned; an error message otherwise.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
| 3301100 | The location switch is off. | |3301100 | The location switch is off.|
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
var locations = [ try {
{"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true}, geoLocationManager.enableLocationMock();
{"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true}, } catch (err) {
{"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true}, console.error("errCode:" + err.code + ",errMessage:" + err.message);
{"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};
geoLocationManager.setMockedLocations(config, (err, data) => {
if (err) {
console.log('setMockedLocations: err=' + JSON.stringify(err));
} }
});
``` ```
## geoLocationManager.setMockedLocations
setMockedLocations(config: LocationMockConfig): Promise&lt;void&gt;; ## geoLocationManager.disableLocationMock
Sets the mock location information. The mock locations will be reported at the interval specified in this API. disableLocationMock(): void;
Disables the mock location function.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
**System API**: 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.
**Parameters**
| Name| Type | Mandatory| Description |
| ------ | ----------------------------------------- | ---- | ------------------------------------------------------------ |
| config | [LocationMockConfig](#locationmockconfig) | Yes | Mock location information, including the interval for reporting the mock locations and the array of the mock locations.|
**Return value**
| Name | Type| Mandatory| Description |
| ------------------- | ---- | ---- | ------------------------------------------------------------ |
| Promise&lt;void&gt; | void | No | Promise used to return the result indicating whether it is successful to set the information. If so, **nullptr** is returned; an error message otherwise.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
| 3301100 | The location switch is off. | |3301100 | The location switch is off.|
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
var locations = [ try {
{"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true}, geoLocationManager.disableLocationMock();
{"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true}, } catch (err) {
{"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true}, console.error("errCode:" + err.code + ",errMessage:" + err.message);
{"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};
geoLocationManager.setMockedLocations(config)
.then((result) => {
console.log('promise, setMockedLocations succeed');
})
.catch((error) => {
if (error) {
console.log('promise, setMockedLocations: error=' + JSON.stringify(error));
} }
});
``` ```
## geoLocationManager.enableReverseGeocodingMock ## geoLocationManager.setMockedLocations
enableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;): void; setMockedLocations(config: LocationMockConfig): void;
Enables the mock reverse geocoding function. Sets the mock location information. The mock locations will be reported at the interval specified in this API.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
...@@ -790,33 +1718,42 @@ Enables the mock reverse geocoding function. ...@@ -790,33 +1718,42 @@ Enables the mock reverse geocoding function.
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| -------- | ------------------------- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result indicating whether it is successful to enable the function. If so, **nullptr** is returned; an error message otherwise.| | config | [LocationMockConfig](#locationmockconfig) | Yes| Mock location information, including the interval for reporting the mock locations and the array of the mock locations.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
|3301100 | The location switch is off.|
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.enableReverseGeocodingMock((err, data) => { var locations = [
if (err) { {"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true},
console.log('enableReverseGeocodingMock: err=' + JSON.stringify(err)); {"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};
try {
geoLocationManager.setMockedLocations(config);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
} }
});
``` ```
## geoLocationManager.enableReverseGeocodingMock ## geoLocationManager.enableReverseGeocodingMock
enableReverseGeocodingMock(): Promise&lt;void&gt;; enableReverseGeocodingMock(): void;
Enables the mock reverse geocoding function. Enables the mock reverse geocoding function.
...@@ -824,39 +1761,29 @@ Enables the mock reverse geocoding function. ...@@ -824,39 +1761,29 @@ Enables the mock reverse geocoding function.
**System API**: 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.
**Return value**
| Name | Type| Mandatory| Description |
| ------------------- | ---- | ---- | ------------------------------------------------------------ |
| Promise&lt;void&gt; | void | No | Promise used to return the result indicating whether it is successful to enable the function. If so, **nullptr** is returned; an error message otherwise.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.enableReverseGeocodingMock() try {
.then((result) => { geoLocationManager.enableReverseGeocodingMock();
console.log('promise, enableReverseGeocodingMock succeed'); } catch (err) {
}) console.error("errCode:" + err.code + ",errMessage:" + err.message);
.catch((error) => {
if (error) {
console.log('promise, enableReverseGeocodingMock: error=' + JSON.stringify(error));
} }
});
``` ```
## geoLocationManager.disableReverseGeocodingMock ## geoLocationManager.disableReverseGeocodingMock
disableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;): void; disableReverseGeocodingMock(): void;
Disables the mock geocoding function. Disables the mock geocoding function.
...@@ -864,166 +1791,147 @@ Disables the mock geocoding function. ...@@ -864,166 +1791,147 @@ Disables the mock geocoding function.
**System API**: 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.
**Parameters**
| Name | Type | Mandatory| Description |
| -------- | ------------------------- | ---- | ------------------------------------------------------------ |
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result indicating whether it is successful to disable the function. If so, **nullptr** is returned; an error message otherwise.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.disableReverseGeocodingMock((err, result) => { try {
if (err) { geoLocationManager.disableReverseGeocodingMock();
console.log('disableReverseGeocodingMock: err=' + JSON.stringify(err)); } catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
} }
});
``` ```
## geoLocationManager.disableReverseGeocodingMock ## geoLocationManager.setReverseGeocodingMockInfo
disableReverseGeocodingMock(): Promise&lt;void&gt;; setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;): void;
Disables the mock reverse geocoding function. Sets information of the mock reverse geocoding function, including the mapping between a location and geographical name. If the location is contained in the configurations during reverse geocoding query, the corresponding geographical name will be returned.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
**System API**: 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.
**Return value** **Parameters**
| Name | Type| Mandatory| Description | | Name| Type| Mandatory| Description|
| ------------------- | ---- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| Promise&lt;void&gt; | void | No | Promise used to return the result indicating whether it is successful to disable the function. If so, **nullptr** is returned; an error message otherwise.| | mockInfos | Array&lt;[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)&gt; | Yes| Array of information of the mock reverse geocoding function, including a location and a geographical name.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.disableReverseGeocodingMock() var mockInfos = [
.then((result) => { {"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
console.log('promise, disableReverseGeocodingMock succeed'); {"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
}) {"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
.catch((error) => { {"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
if (error) { {"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
console.log('promise, disableReverseGeocodingMock: error=' + JSON.stringify(error)); ];
try {
geoLocationManager.setReverseGeocodingMockInfo(mockInfos);
} catch (err) {
console.error("errCode:" + err.code + ",errMessage:" + err.message);
} }
});
``` ```
## geoLocationManager.setReverseGeocodingMockInfo ## geoLocationManager.isLocationPrivacyConfirmed
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;, callback: AsyncCallback&lt;void&gt;): void;
Sets information of the mock reverse geocoding function, including the mapping between a location and geographical name. If the location is contained in the configurations during reverse geocoding query, the corresponding geographical name will be returned. isLocationPrivacyConfirmed(type: LocationPrivacyType): boolean;
**System capability**: SystemCapability.Location.Location.Core Checks whether a user agrees with the privacy statement of the location service. This API can only be called by system applications.
**System API**: 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.
**System capability**: SystemCapability.Location.Location.Core
**Parameters** **Parameters**
| Name | Type | Mandatory| Description | | Name| Type| Mandatory| Description|
| --------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)&gt; | Yes | Array of information of the mock reverse geocoding function, including a location and a geographical name.| | type | [LocationPrivacyType](#locationprivacytype)| Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when the location service is enabled.|
| callback | AsyncCallback&lt;void&gt; | Yes | Callback used to return the result indicating whether it is successful to set the information. If so, **nullptr** is returned; an error message otherwise.|
**Return value**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| boolean | boolean | NA | Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
var mockInfos = [ try {
{"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}}, var isConfirmed = geoLocationManager.isLocationPrivacyConfirmed(1);
{"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}}, } catch (err) {
{"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}}, console.error("errCode:" + err.code + ",errMessage:" + err.message);
{"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geoLocationManager.setReverseGeocodingMockInfo(mockInfos, (err, data) => {
if (err) {
console.log('promise, setReverseGeocodingMockInfo, err:' + JSON.stringify(err));
} }
});
``` ```
## geoLocationManager.setReverseGeocodingMockInfo ## geoLocationManager.setLocationPrivacyConfirmStatus
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;): Promise&lt;void&gt;;
Sets information of the mock reverse geocoding function, including the mapping between a location and geographical name. If the location is contained in the configurations during reverse geocoding query, the corresponding geographical name will be returned. setLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean): void;
**System capability**: SystemCapability.Location.Location.Core Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications.
**System API**: 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.
**Parameters** **Required permissions**: ohos.permission.MANAGE_SECURE_SETTINGS
| Name | Type | Mandatory| Description | **System capability**: SystemCapability.Location.Location.Core
| --------- | ------------------------------------------------------------ | ---- | ------------------------------------------------------------ |
| mockInfos | Array&lt;[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)&gt; | Yes | Array of information of the mock reverse geocoding function, including a location and a geographical name.|
**Return value** **Parameters**
| Name | Type| Mandatory| Description | | Name| Type| Mandatory| Description|
| ------------------- | ---- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- |
| Promise&lt;void&gt; | void | No | Promise used to return the result indicating whether it is successful to set the information. If so, **nullptr** is returned; an error message otherwise.| | type | [LocationPrivacyType](#locationprivacytype) | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when the location service is enabled.|
| isConfirmed | boolean | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
**Error codes** **Error codes**
For details about the following error codes, see [error codes of the location service](../errorcodes/errorcode-geoLocationManager.md). For details about the following error codes, see [Location Error Codes](../errorcodes/errorcode-geoLocationManager.md).
| Code| Error Message | | ID| Error Message|
| -------- | -------------------------------- | | -------- | ---------------------------------------- |
| 3301000 | Location service is unavailable. | |3301000 | Location service is unavailable. |
**Example** **Example**
```ts ```ts
import geoLocationManager from '@ohos.geoLocationManager'; import geoLocationManager from '@ohos.geoLocationManager';
var mockInfos = [ try {
{"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}}, geoLocationManager.setLocationPrivacyConfirmStatus(1, true);
{"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}}, } catch (err) {
{"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}}, console.error("errCode:" + err.code + ",errMessage:" + err.message);
{"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geoLocationManager.setReverseGeocodingMockInfo(mockInfos)
.then((result) => {
console.log('promise, setReverseGeocodingMockInfo succeed');
})
.catch((error) => {
if (error) {
console.log('promise, setReverseGeocodingMockInfo: error=' + JSON.stringify(error));
} }
});
``` ```
...@@ -1033,11 +1941,11 @@ Sets the priority of the location request. ...@@ -1033,11 +1941,11 @@ Sets the priority of the location request.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
| Name | Value | Description | | Name| Value| Description|
| --------- | ----- | ------------------------------------------------------------ | | -------- | -------- | -------- |
| UNSET | 0x200 | Priority unspecified. | | UNSET | 0x200 | Priority unspecified.|
| ACCURACY | 0x201 | Location accuracy. | | ACCURACY | 0x201 | Location accuracy.|
| LOW_POWER | 0x202 | Power efficiency. | | LOW_POWER | 0x202 | Power efficiency.|
| FIRST_FIX | 0x203 | Fast location. Use this option if you want to obtain a location as fast as possible.| | FIRST_FIX | 0x203 | Fast location. Use this option if you want to obtain a location as fast as possible.|
...@@ -1047,13 +1955,13 @@ Sets the priority of the location request. ...@@ -1047,13 +1955,13 @@ Sets the priority of the location request.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
| Name | Value | Description | | Name| Value| Description|
| ------------------- | ----- | ------------------------------------------------------------ | | -------- | -------- | -------- |
| UNSET | 0x300 | Scenario unspecified. | | UNSET | 0x300 | Scenario unspecified.|
| NAVIGATION | 0x301 | Navigation. | | NAVIGATION | 0x301 | Navigation.|
| TRAJECTORY_TRACKING | 0x302 | Trajectory tracking. | | TRAJECTORY_TRACKING | 0x302 | Trajectory tracking.|
| CAR_HAILING | 0x303 | Ride hailing. | | CAR_HAILING | 0x303 | Ride hailing.|
| DAILY_LIFE_SERVICE | 0x304 | Daily life services. | | DAILY_LIFE_SERVICE | 0x304 | Daily life services.|
| NO_POWER | 0x305 | Power efficiency. Your application does not proactively start the location service. When responding to another application requesting the same location service, the system marks a copy of the location result to your application. In this way, your application will not consume extra power for obtaining the user location.| | NO_POWER | 0x305 | Power efficiency. Your application does not proactively start the location service. When responding to another application requesting the same location service, the system marks a copy of the location result to your application. In this way, your application will not consume extra power for obtaining the user location.|
...@@ -1063,12 +1971,12 @@ Defines a reverse geocoding request. ...@@ -1063,12 +1971,12 @@ Defines a reverse geocoding request.
**System capability**: SystemCapability.Location.Location.Geocoder **System capability**: SystemCapability.Location.Location.Geocoder
| Name | Type | Readable| Writable| Description | | Name| Type| Readable| Writable| Description|
| --------- | ------ | ---- | ---- | ---------------------------------------------------- | | -------- | -------- | -------- | -------- | -------- |
| locale | string | Yes | Yes | Language used for the location description. **zh** indicates Chinese, and **en** indicates English.| | locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| latitude | number | Yes | Yes | Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. | | latitude | number | Yes| Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude | number | Yes | Yes | Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . | | longitude | number | Yes| Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| maxItems | number | Yes | Yes | Maximum number of location records to be returned. | | maxItems | number | Yes| Yes| Maximum number of location records to be returned.|
## GeoCodeRequest ## GeoCodeRequest
...@@ -1077,15 +1985,15 @@ Defines a geocoding request. ...@@ -1077,15 +1985,15 @@ Defines a geocoding request.
**System capability**: SystemCapability.Location.Location.Geocoder **System capability**: SystemCapability.Location.Location.Geocoder
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| ------------ | ------ | ---- | ---- | ---------------------------------------------------------- | | -------- | -------- | -------- | -------- | -------- |
| locale | string | Yes | Yes | Language used for the location description. **zh** indicates Chinese, and **en** indicates English. | | locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| description | string | Yes | Yes | Location description, for example, **No. xx, xx Road, Pudong New District, Shanghai**. | | description | string | Yes| Yes| Location description, for example, **No. xx, xx Road, Pudong New District, Shanghai**.|
| maxItems | number | Yes | Yes | Maximum number of location records to be returned. | | maxItems | number | Yes| Yes| Maximum number of location records to be returned.|
| minLatitude | number | Yes | Yes | Minimum latitude. This parameter is used with **minLongitude**, **maxLatitude**, and **maxLongitude** to specify the latitude and longitude ranges.| | minLatitude | number | Yes| Yes| Minimum latitude. This parameter is used with **minLongitude**, **maxLatitude**, and **maxLongitude** to specify the latitude and longitude ranges.|
| minLongitude | number | Yes | Yes | Minimum longitude. | | minLongitude | number | Yes| Yes| Minimum longitude.|
| maxLatitude | number | Yes | Yes | Maximum latitude. | | maxLatitude | number | Yes| Yes| Maximum latitude.|
| maxLongitude | number | Yes | Yes | Maximum longitude. | | maxLongitude | number | Yes| Yes| Maximum longitude.|
## GeoAddress ## GeoAddress
...@@ -1094,27 +2002,27 @@ Defines a geographic location. ...@@ -1094,27 +2002,27 @@ Defines a geographic location.
**System capability**: SystemCapability.Location.Location.Geocoder **System capability**: SystemCapability.Location.Location.Geocoder
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| --------------------- | ------------------- | ---- | ---- | ---------------------------------------------------- | | -------- | -------- | -------- | -------- | -------- |
| latitude | number | Yes | No | Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. | | latitude | number | Yes| No | Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude | number | Yes | No | Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . | | longitude | number | Yes| No | Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| locale | string | Yes | No | Language used for the location description. **zh** indicates Chinese, and **en** indicates English.| | locale | string | Yes| No | Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| placeName | string | Yes | No | Landmark of the location. | | placeName | string | Yes| No | Landmark of the location.|
| countryCode | string | Yes | No | Country code. | | countryCode | string | Yes| No | Country code.|
| countryName | string | Yes | No | Country name. | | countryName | string| Yes| No| Country name.|
| administrativeArea | string | Yes | No | Administrative region name. | | administrativeArea | string | Yes| No| Administrative region name.|
| subAdministrativeArea | string | Yes | No | Sub-administrative region name. | | subAdministrativeArea | string | Yes| No| Sub-administrative region name.|
| locality | string | Yes | No | Locality information. | | locality | string | Yes| No| Locality information.|
| subLocality | string | Yes | No | Sub-locality information. | | subLocality | string | Yes| No| Sub-locality information.|
| roadName | string | Yes | No | Road name. | | roadName | string | Yes| No|Road name.|
| subRoadName | string | Yes | No | Auxiliary road information. | | subRoadName | string | Yes| No| Auxiliary road information.|
| premises | string | Yes | No | House information. | | premises | string| Yes| No|House information.|
| postalCode | string | Yes | No | Postal code. | | postalCode | string | Yes| No| Postal code.|
| phoneNumber | string | Yes | No | Phone number. | | phoneNumber | string | Yes| No| Phone number.|
| addressUrl | string | Yes | No | Website URL. | | addressUrl | string | Yes| No| Website URL.|
| descriptions | Array&lt;string&gt; | Yes | No | Additional descriptions. | | descriptions | Array&lt;string&gt; | Yes| No| Additional descriptions.|
| descriptionsSize | number | Yes | No | Total number of additional descriptions. | | descriptionsSize | number | Yes| No| Total number of additional descriptions.|
| isFromMock | Boolean | Yes | No | Whether the geographical name is from the mock reverse geocoding function. | | isFromMock | Boolean | Yes| No| Whether the geographical name is from the mock reverse geocoding function.|
## LocationRequest ## LocationRequest
...@@ -1123,13 +2031,13 @@ Defines a location request. ...@@ -1123,13 +2031,13 @@ Defines a location request.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| ---------------- | --------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes | Yes | Priority of the location request. | | priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes | Yes | Scenario of the location request. | | scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request.|
| timeInterval | number | Yes | Yes | Time interval at which location information is reported. | | timeInterval | number | Yes| Yes| Time interval at which location information is reported.|
| distanceInterval | number | Yes | Yes | Distance interval at which location information is reported. | | distanceInterval | number | Yes| Yes| Distance interval at which location information is reported.|
| maxAccuracy | number | Yes | Yes | Location accuracy. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled.| | maxAccuracy | number | Yes| Yes| Location accuracy. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled.|
## CurrentLocationRequest ## CurrentLocationRequest
...@@ -1138,12 +2046,12 @@ Defines the current location request. ...@@ -1138,12 +2046,12 @@ Defines the current location request.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| ----------- | --------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes | Yes | Priority of the location request. | | priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes | Yes | Scenario of the location request. | | scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request.|
| maxAccuracy | number | Yes | Yes | Location accuracy, in meters. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled.| | maxAccuracy | number | Yes| Yes| Location accuracy, in meters. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled.|
| timeoutMs | number | Yes | Yes | Timeout duration, in milliseconds. The minimum value is **1000**. | | timeoutMs | number | Yes| Yes| Timeout duration, in milliseconds. The minimum value is **1000**.|
## SatelliteStatusInfo ## SatelliteStatusInfo
...@@ -1152,14 +2060,14 @@ Defines the satellite status information. ...@@ -1152,14 +2060,14 @@ Defines the satellite status information.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| ---------------------- | ------------------- | ---- | ---- | --------------------------------- | | -------- | -------- | -------- | -------- | -------- |
| satellitesNumber | number | Yes | No | Number of satellites. | | satellitesNumber | number | Yes| No| Number of satellites.|
| satelliteIds | Array&lt;number&gt; | Yes | No | Array of satellite IDs. | | satelliteIds | Array&lt;number&gt; | Yes| No| Array of satellite IDs.|
| carrierToNoiseDensitys | Array&lt;number&gt; | Yes | No | Carrier-to-noise density ratio, that is, **cn0**.| | carrierToNoiseDensitys | Array&lt;number&gt; | Yes| No| Carrier-to-noise density ratio, that is, **cn0**.|
| altitudes | Array&lt;number&gt; | Yes | No | Altitude information. | | altitudes | Array&lt;number&gt; | Yes| No| Altitude information.|
| azimuths | Array&lt;number&gt; | Yes | No | Azimuth information. | | azimuths | Array&lt;number&gt; | Yes| No| Azimuth information.|
| carrierFrequencies | Array&lt;number&gt; | Yes | No | Carrier frequency. | | carrierFrequencies | Array&lt;number&gt; | Yes| No| Carrier frequency.|
## CachedGnssLocationsRequest ## CachedGnssLocationsRequest
...@@ -1168,10 +2076,10 @@ Represents a request for reporting cached GNSS locations. ...@@ -1168,10 +2076,10 @@ Represents a request for reporting cached GNSS locations.
**System capability**: SystemCapability.Location.Location.Gnss **System capability**: SystemCapability.Location.Location.Gnss
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| -------------------- | ------- | ---- | ---- | ------------------------------------------------------------ | | -------- | -------- | -------- | -------- | -------- |
| reportingPeriodSec | number | Yes | Yes | Interval for reporting the cached GNSS locations, in milliseconds. | | reportingPeriodSec | number | Yes| Yes| Interval for reporting the cached GNSS locations, in milliseconds.|
| wakeUpCacheQueueFull | boolean | Yes | Yes | **true**: reports the cached GNSS locations to the application when the cache queue is full.<br />**false**: discards the cached GNSS locations when the cache queue is full. | | wakeUpCacheQueueFull | boolean | Yes| Yes | **true**: reports the cached GNSS locations to the application when the cache queue is full.<br>**false**: discards the cached GNSS locations when the cache queue is full.|
## Geofence ## Geofence
...@@ -1180,12 +2088,12 @@ Defines a GNSS geofence. Currently, only circular geofences are supported. ...@@ -1180,12 +2088,12 @@ Defines a GNSS geofence. Currently, only circular geofences are supported.
**System capability**: SystemCapability.Location.Location.Geofence **System capability**: SystemCapability.Location.Location.Geofence
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| ---------- | ------ | ---- | ---- | ---------------------------- | | -------- | -------- | -------- | -------- | -------- |
| latitude | number | Yes | Yes | Latitude information. | | latitude | number | Yes| Yes|Latitude information.|
| longitude | number | Yes | Yes | Longitude information. | | longitude | number | Yes|Yes| Longitude information.|
| radius | number | Yes | Yes | Radius of a circular geofence. | | radius | number | Yes|Yes| Radius of a circular geofence.|
| expiration | number | Yes | Yes | Expiration period of a geofence, in milliseconds.| | expiration | number | Yes|Yes| Expiration period of a geofence, in milliseconds.|
## GeofenceRequest ## GeofenceRequest
...@@ -1194,11 +2102,10 @@ Represents a GNSS geofencing request. ...@@ -1194,11 +2102,10 @@ Represents a GNSS geofencing request.
**System capability**: SystemCapability.Location.Location.Geofence **System capability**: SystemCapability.Location.Location.Geofence
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| -------- | --------------------------------------------------- | ---- | ---- | -------------------- | | -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes | Yes | Priority of the location information.| | scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes | Location scenario.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes | Yes | Location scenario. | | geofence | [Geofence](#geofence)| Yes| Yes | Geofence information.|
| geofence | [Geofence](#geofence) | Yes | Yes | Geofence information. |
## LocationPrivacyType ## LocationPrivacyType
...@@ -1207,10 +2114,10 @@ Defines the privacy statement type. ...@@ -1207,10 +2114,10 @@ Defines the privacy statement type.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
| Name | Value | Description | | Name| Value| Description|
| ------------- | ---- | ------------------------------ | | -------- | -------- | -------- |
| OTHERS | 0 | Other scenarios. | | OTHERS | 0 | Other scenarios.|
| STARTUP | 1 | Privacy statement displayed in the startup wizard. | | STARTUP | 1 | Privacy statement displayed in the startup wizard.|
| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.| | CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.|
...@@ -1220,10 +2127,10 @@ Defines an extended command. ...@@ -1220,10 +2127,10 @@ Defines an extended command.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| -------- | --------------------------------------------------- | ---- | ---- | ---------------- | | -------- | -------- | -------- | -------- | -------- |
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes | Yes | Location scenario. | | scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes | Location scenario.|
| command | string | Yes | Yes | Extended command, in the string format.| | command | string | Yes| Yes | Extended command, in the string format.|
## Location ## Location
...@@ -1232,19 +2139,19 @@ Defines a location. ...@@ -1232,19 +2139,19 @@ Defines a location.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| ------------- | ------------------- | ---- | ---- | ------------------------------------------ | | -------- | -------- | -------- | -------- | -------- |
| latitude | number | Yes | No | Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.| | latitude | number| Yes| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude | number | Yes | No | Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .| | longitude | number| Yes| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| altitude | number | Yes | No | Location altitude, in meters. | | altitude | number | Yes| No| Location altitude, in meters.|
| accuracy | number | Yes | No | Location accuracy, in meters. | | accuracy | number | Yes| No| Location accuracy, in meters.|
| speed | number | Yes | No | Speed, in m/s. | | speed | number | Yes| No|Speed, in m/s.|
| timeStamp | number | Yes | No | Location timestamp in the UTC format. | | timeStamp | number | Yes| No| Location timestamp in the UTC format.|
| direction | number | Yes | No | Direction information. | | direction | number | Yes| No| Direction information.|
| timeSinceBoot | number | Yes | No | Location timestamp since boot. | | timeSinceBoot | number | Yes| No| Location timestamp since boot.|
| additions | Array&lt;string&gt; | Yes | No | Additional description. | | additions | Array&lt;string&gt; | Yes| No| Additional description.|
| additionSize | number | Yes | No | Number of additional descriptions. | | additionSize | number | Yes| No| Number of additional descriptions.|
| isFromMock | Boolean | Yes | No | Whether the location information is from the mock location function. | | isFromMock | Boolean | Yes| No| Whether the location information is from the mock location function.|
## ReverseGeocodingMockInfo ## ReverseGeocodingMockInfo
...@@ -1255,10 +2162,10 @@ Represents information of the mock reverse geocoding function. ...@@ -1255,10 +2162,10 @@ Represents information of the mock reverse geocoding function.
**System API**: 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.
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| ---------- | ----------------------------------------------- | ---- | ---- | ---------------- | | -------- | -------- | -------- | -------- | -------- |
| location | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes | Yes | Latitude and longitude information.| | location | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Yes| Latitude and longitude information.|
| geoAddress | [GeoAddress](#geoaddress) | Yes | Yes | Geographical name. | | geoAddress | [GeoAddress](#geoaddress) | Yes| Yes|Geographical name.|
## LocationMockConfig ## LocationMockConfig
...@@ -1269,10 +2176,10 @@ Represents the information of the mock location function. ...@@ -1269,10 +2176,10 @@ Represents the information of the mock location function.
**System API**: 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.
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| ------------ | --------------------- | ---- | ---- | -------------------------------------- | | -------- | -------- | -------- | -------- | -------- |
| timeInterval | number | Yes | Yes | Interval at which mock locations are reported, in seconds.| | timeInterval | number | Yes| Yes| Interval at which mock locations are reported, in seconds.|
| locations | Array&lt;Location&gt; | Yes | Yes | Array of mocked locations. | | locations | Array&lt;Location&gt; | Yes| Yes| Array of mocked locations.|
## CountryCode ## CountryCode
...@@ -1281,10 +2188,10 @@ Represents country code information. ...@@ -1281,10 +2188,10 @@ Represents country code information.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
| Name | Type | Readable| Writable| Description | | Name| Type| Readable|Writable| Description|
| ------- | ----------------------------------- | ---- | ---- | -------------------- | | -------- | -------- | -------- | -------- | -------- |
| country | string | Yes | No | Country code. | | country | string | Yes| No| Country code.|
| type | [CountryCodeType](#countrycodetype) | Yes | No | Country code source.| | type | [CountryCodeType](#countrycodetype) | Yes| No| Country code source.|
## CountryCodeType ## CountryCodeType
...@@ -1293,9 +2200,9 @@ Represents the country code source type. ...@@ -1293,9 +2200,9 @@ Represents the country code source type.
**System capability**: SystemCapability.Location.Location.Core **System capability**: SystemCapability.Location.Location.Core
| Name | Value | Description | | Name| Value| Description|
| -------------------------- | ---- | -------------------------------------------------- | | -------- | -------- | -------- |
| COUNTRY_CODE_FROM_LOCALE | 1 | Country code obtained from the language configuration of the globalization module. | | COUNTRY_CODE_FROM_LOCALE | 1 | Country code obtained from the language configuration of the globalization module.|
| COUNTRY_CODE_FROM_SIM | 2 | Country code obtained from the SIM card. | | COUNTRY_CODE_FROM_SIM | 2 | Country code obtained from the SIM card.|
| COUNTRY_CODE_FROM_LOCATION | 3 | Country code obtained using the reverse geocoding function based on the user's location information.| | COUNTRY_CODE_FROM_LOCATION | 3 | Country code obtained using the reverse geocoding function based on the user's location information.|
| COUNTRY_CODE_FROM_NETWORK | 4 | Country code obtained from the cellular network registration information. | | COUNTRY_CODE_FROM_NETWORK | 4 | Country code obtained from the cellular network registration information.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册