提交 e30e36a0 编写于 作者: L liu-binjun

bugfix:fix maxAccuracy description

Signed-off-by: Nliu-binjun <liubinjun@huawei.com>
上级 19b0f85e
......@@ -14,7 +14,7 @@ import geolocation from '@ohos.geolocation';
## geolocation.on('locationChange')
on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Location&gt;) : void
on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Location&gt;): void
Registers a listener for location changes with a location request initiated.
......@@ -34,6 +34,7 @@ Registers a listener for location changes with a location request initiated.
**Example**
```js
import geolocation from '@ohos.geolocation';
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
......@@ -44,7 +45,7 @@ Registers a listener for location changes with a location request initiated.
## geolocation.off('locationChange')
off(type: 'locationChange', callback?: Callback&lt;Location&gt;) : void
off(type: 'locationChange', callback?: Callback&lt;Location&gt;): void
Unregisters the listener for location changes with the corresponding location request deleted.
......@@ -63,6 +64,7 @@ Unregisters the listener for location changes with the corresponding location re
**Example**
```js
import geolocation from '@ohos.geolocation';
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
......@@ -74,7 +76,7 @@ Unregisters the listener for location changes with the corresponding location re
## geolocation.on('locationServiceState')
on(type: 'locationServiceState', callback: Callback&lt;boolean&gt;) : void
on(type: 'locationServiceState', callback: Callback&lt;boolean&gt;): void
Registers a listener for location service status change events.
......@@ -93,6 +95,7 @@ Registers a listener for location service status change events.
**Example**
```js
import geolocation from '@ohos.geolocation';
var locationServiceState = (state) => {
console.log('locationServiceState: ' + JSON.stringify(state));
}
......@@ -102,7 +105,7 @@ Registers a listener for location service status change events.
## geolocation.off('locationServiceState')
off(type: 'locationServiceState', callback?: Callback&lt;boolean&gt;) : void;
off(type: 'locationServiceState', callback?: Callback&lt;boolean&gt;): void;
Unregisters the listener for location service status change events.
......@@ -121,6 +124,7 @@ Unregisters the listener for location service status change events.
**Example**
```js
import geolocation from '@ohos.geolocation';
var locationServiceState = (state) => {
console.log('locationServiceState: state: ' + JSON.stringify(state));
}
......@@ -131,7 +135,7 @@ Unregisters the listener for location service status change events.
## geolocation.on('cachedGnssLocationsReporting')<sup>8+</sup>
on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, callback: Callback&lt;Array&lt;Location&gt;&gt;) : void;
on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, callback: Callback&lt;Array&lt;Location&gt;&gt;): void;
Registers a listener for cached GNSS location reports.
......@@ -151,6 +155,7 @@ Registers a listener for cached GNSS location reports.
**Example**
```js
import geolocation from '@ohos.geolocation';
var cachedLocationsCb = (locations) => {
console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
}
......@@ -161,7 +166,7 @@ Registers a listener for cached GNSS location reports.
## geolocation.off('cachedGnssLocationsReporting')<sup>8+</sup>
off(type: 'cachedGnssLocationsReporting', callback?: Callback&lt;Array&lt;Location&gt;&gt;) : void;
off(type: 'cachedGnssLocationsReporting', callback?: Callback&lt;Array&lt;Location&gt;&gt;): void;
Unregisters the listener for cached GNSS location reports.
......@@ -180,6 +185,7 @@ Unregisters the listener for cached GNSS location reports.
**Example**
```js
import geolocation from '@ohos.geolocation';
var cachedLocationsCb = (locations) => {
console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
}
......@@ -191,7 +197,7 @@ Unregisters the listener for cached GNSS location reports.
## geolocation.on('gnssStatusChange')<sup>8+</sup>
on(type: 'gnssStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;) : void;
on(type: 'gnssStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;): void;
Registers a listener for GNSS satellite status change events.
......@@ -210,6 +216,7 @@ Registers a listener for GNSS satellite status change events.
**Example**
```js
import geolocation from '@ohos.geolocation';
var gnssStatusCb = (satelliteStatusInfo) => {
console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
......@@ -219,7 +226,7 @@ Registers a listener for GNSS satellite status change events.
## geolocation.off('gnssStatusChange')<sup>8+</sup>
off(type: 'gnssStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;) : void;
off(type: 'gnssStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;): void;
Unregisters the listener for GNSS satellite status change events.
......@@ -237,6 +244,7 @@ Unregisters the listener for GNSS satellite status change events.
**Example**
```js
import geolocation from '@ohos.geolocation';
var gnssStatusCb = (satelliteStatusInfo) => {
console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
......@@ -247,7 +255,7 @@ Unregisters the listener for GNSS satellite status change events.
## geolocation.on('nmeaMessageChange')<sup>8+</sup>
on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;) : void;
on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;): void;
Registers a listener for GNSS NMEA message change events.
......@@ -266,6 +274,7 @@ Registers a listener for GNSS NMEA message change events.
**Example**
```js
import geolocation from '@ohos.geolocation';
var nmeaCb = (str) => {
console.log('nmeaMessageChange: ' + JSON.stringify(str));
}
......@@ -275,7 +284,7 @@ Registers a listener for GNSS NMEA message change events.
## geolocation.off('nmeaMessageChange')<sup>8+</sup>
off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;) : void;
off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;): void;
Unregisters the listener for GNSS NMEA message change events.
......@@ -294,6 +303,7 @@ Unregisters the listener for GNSS NMEA message change events.
**Example**
```js
import geolocation from '@ohos.geolocation';
var nmeaCb = (str) => {
console.log('nmeaMessageChange: ' + JSON.stringify(str));
}
......@@ -304,7 +314,7 @@ Unregisters the listener for GNSS NMEA message change events.
## geolocation.on('fenceStatusChange')<sup>8+</sup>
on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void;
on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
Registers a listener for status change events of the specified geofence.
......@@ -331,13 +341,13 @@ Registers a listener for status change events of the specified geofence.
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility"
abilityName: "com.example.myapplication.MainAbility",
action: "action1",
}
],
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG],
};
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
......@@ -349,7 +359,7 @@ Registers a listener for status change events of the specified geofence.
## geolocation.off('fenceStatusChange')<sup>8+</sup>
off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void;
off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
Unregisters the listener for status change events of the specified geofence.
......@@ -375,7 +385,7 @@ Unregisters the listener for status change events of the specified geofence.
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility"
abilityName: "com.example.myapplication.MainAbility",
action: "action1",
}
],
......@@ -392,62 +402,9 @@ Unregisters the listener for status change events of the specified geofence.
```
## geolocation.on('countryCodeChange')<sup>9+</sup>
on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;) : void;
Subscribe to country code information reporting events.
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is "countrycodechange", which means subscribing to the submission of country code information. |
| callback | Callback&lt;CountryCode&gt; | Yes | Callback is used to receive the country code information report. |
**Example**
```js
var callback = (code) => {
console.log('countryCodeChange: ' + JSON.stringify(code));
}
geolocation.on('countryCodeChange', callback);
```
## geolocation.off('countryCodeChange')<sup>9+</sup>
off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;) : void;
Unsubscribe from the country code to report events.
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | string | Yes| Event type. The value is "countrycodechange", which means unsubscribing to the submission of country code information. |
| callback | Callback&lt;CountryCode&gt; | Yes | Callback is used to receive the country code information report. |
**Example**
```js
var callback = (code) => {
console.log('countryCodeChange: ' + JSON.stringify(code));
}
geolocation.on('countryCodeChange', callback);
geolocation.off('countryCodeChange', callback);
```
## geolocation.getCurrentLocation
getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;Location&gt;) : void
getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;Location&gt;): void
Obtains the current location. This API uses an asynchronous callback to return the result.
......@@ -466,6 +423,7 @@ Obtains the current location. This API uses an asynchronous callback to return t
**Example**
```js
import geolocation from '@ohos.geolocation';
var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
var locationChange = (err, location) => {
if (err) {
......@@ -482,7 +440,7 @@ Obtains the current location. This API uses an asynchronous callback to return t
## geolocation.getCurrentLocation
getCurrentLocation(request?: CurrentLocationRequest) : Promise&lt;Location&gt;
getCurrentLocation(request?: CurrentLocationRequest): Promise&lt;Location&gt;
Obtains the current location. This API uses a promise to return the result.
......@@ -507,6 +465,7 @@ Obtains the current location. This API uses a promise to return the result.
**Example**
```js
import geolocation from '@ohos.geolocation';
var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
geolocation.getCurrentLocation(requestInfo).then((result) => {
console.log('current location: ' + JSON.stringify(result));
......@@ -516,7 +475,7 @@ Obtains the current location. This API uses a promise to return the result.
## geolocation.getLastLocation
getLastLocation(callback: AsyncCallback&lt;Location&gt;) : void
getLastLocation(callback: AsyncCallback&lt;Location&gt;): void
Obtains the previous location. This API uses an asynchronous callback to return the result.
......@@ -534,6 +493,7 @@ Obtains the previous location. This API uses an asynchronous callback to return
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.getLastLocation((err, data) => {
if (err) {
console.log('getLastLocation: err=' + JSON.stringify(err));
......@@ -547,7 +507,7 @@ Obtains the previous location. This API uses an asynchronous callback to return
## geolocation.getLastLocation
getLastLocation() : Promise&lt;Location&gt;
getLastLocation(): Promise&lt;Location&gt;
Obtains the previous location. This API uses a promise to return the result.
......@@ -565,6 +525,7 @@ Obtains the previous location. This API uses a promise to return the result.
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.getLastLocation().then((result) => {
console.log('getLastLocation: result: ' + JSON.stringify(result));
});
......@@ -573,7 +534,7 @@ Obtains the previous location. This API uses a promise to return the result.
## geolocation.isLocationEnabled
isLocationEnabled(callback: AsyncCallback&lt;boolean&gt;) : void
isLocationEnabled(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the location service is enabled. This API uses an asynchronous callback to return the result.
......@@ -591,6 +552,7 @@ Checks whether the location service is enabled. This API uses an asynchronous ca
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.isLocationEnabled((err, data) => {
if (err) {
console.log('isLocationEnabled: err=' + JSON.stringify(err));
......@@ -604,7 +566,7 @@ Checks whether the location service is enabled. This API uses an asynchronous ca
## geolocation.isLocationEnabled
isLocationEnabled() : Promise&lt;boolean&gt;
isLocationEnabled(): Promise&lt;boolean&gt;
Checks whether the location service is enabled. This API uses a promise to return the result.
......@@ -621,15 +583,16 @@ Checks whether the location service is enabled. This API uses a promise to retur
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.isLocationEnabled().then((result) => {
console.log('promise, isLocationEnabled: ' + result);
console.log('promise, isLocationEnabled: ' + JSON.stringify(result));
});
```
## geolocation.requestEnableLocation
requestEnableLocation(callback: AsyncCallback&lt;boolean&gt;) : void
requestEnableLocation(callback: AsyncCallback&lt;boolean&gt;): void
Requests to enable the location service. This API uses an asynchronous callback to return the result.
......@@ -647,6 +610,7 @@ Requests to enable the location service. This API uses an asynchronous callback
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.requestEnableLocation((err, data) => {
if (err) {
console.log('requestEnableLocation: err=' + JSON.stringify(err));
......@@ -660,7 +624,7 @@ Requests to enable the location service. This API uses an asynchronous callback
## geolocation.requestEnableLocation
requestEnableLocation() : Promise&lt;boolean&gt;
requestEnableLocation(): Promise&lt;boolean&gt;
Requests to enable the location service. This API uses a promise to return the result.
......@@ -677,6 +641,7 @@ Requests to enable the location service. This API uses a promise to return the r
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.requestEnableLocation().then((result) => {
console.log('promise, requestEnableLocation: ' + JSON.stringify(result));
});
......@@ -685,7 +650,7 @@ Requests to enable the location service. This API uses a promise to return the r
## geolocation.enableLocation
enableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
enableLocation(callback: AsyncCallback&lt;boolean&gt;): void;
Enables the location service. This API uses an asynchronous callback to return the result.
......@@ -704,6 +669,7 @@ Enables the location service. This API uses an asynchronous callback to return t
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.enableLocation((err, data) => {
if (err) {
console.log('enableLocation: err=' + JSON.stringify(err));
......@@ -717,7 +683,7 @@ Enables the location service. This API uses an asynchronous callback to return t
## geolocation.enableLocation
enableLocation() : Promise&lt;boolean&gt;
enableLocation(): Promise&lt;boolean&gt;
Enables the location service. This API uses a promise to return the result.
......@@ -736,6 +702,7 @@ Enables the location service. This API uses a promise to return the result.
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.enableLocation().then((result) => {
console.log('promise, enableLocation: ' + JSON.stringify(result));
});
......@@ -743,7 +710,7 @@ Enables the location service. This API uses a promise to return the result.
## geolocation.disableLocation
disableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
disableLocation(callback: AsyncCallback&lt;boolean&gt;): void;
Disables the location service. This API uses an asynchronous callback to return the result.
......@@ -762,6 +729,7 @@ Disables the location service. This API uses an asynchronous callback to return
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.disableLocation((err, data) => {
if (err) {
console.log('disableLocation: err=' + JSON.stringify(err));
......@@ -775,7 +743,7 @@ Disables the location service. This API uses an asynchronous callback to return
## geolocation.disableLocation
disableLocation() : Promise&lt;boolean&gt;
disableLocation(): Promise&lt;boolean&gt;
Disables the location service. This API uses a promise to return the result.
......@@ -794,6 +762,7 @@ Disables the location service. This API uses a promise to return the result.
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.disableLocation().then((result) => {
console.log('promise, disableLocation: ' + JSON.stringify(result));
});
......@@ -801,7 +770,7 @@ Disables the location service. This API uses a promise to return the result.
## geolocation.isGeoServiceAvailable
isGeoServiceAvailable(callback: AsyncCallback&lt;boolean&gt;) : void
isGeoServiceAvailable(callback: AsyncCallback&lt;boolean&gt;): void
Checks whether the (reverse) geocoding service is available. This API uses an asynchronous callback to return the result.
......@@ -818,6 +787,7 @@ Checks whether the (reverse) geocoding service is available. This API uses an as
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.isGeoServiceAvailable((err, data) => {
if (err) {
console.log('isGeoServiceAvailable: err=' + JSON.stringify(err));
......@@ -831,7 +801,7 @@ Checks whether the (reverse) geocoding service is available. This API uses an as
## geolocation.isGeoServiceAvailable
isGeoServiceAvailable() : Promise&lt;boolean&gt;
isGeoServiceAvailable(): Promise&lt;boolean&gt;
Checks whether the (reverse) geocoding service is available. This API uses a promise to return the result.
......@@ -848,6 +818,7 @@ Checks whether the (reverse) geocoding service is available. This API uses a pro
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.isGeoServiceAvailable().then((result) => {
console.log('promise, isGeoServiceAvailable: ' + JSON.stringify(result));
});
......@@ -856,7 +827,7 @@ Checks whether the (reverse) geocoding service is available. This API uses a pro
## geolocation.getAddressesFromLocation
getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;) : void
getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
Converts coordinates into geographic description through reverse geocoding. This API uses an asynchronous callback to return the result.
......@@ -874,6 +845,7 @@ Converts coordinates into geographic description through reverse geocoding. This
**Example**
```js
import geolocation from '@ohos.geolocation';
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
if (err) {
......@@ -888,7 +860,7 @@ Converts coordinates into geographic description through reverse geocoding. This
## geolocation.getAddressesFromLocation
getAddressesFromLocation(request: ReverseGeoCodeRequest) : Promise&lt;Array&lt;GeoAddress&gt;&gt;;
getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;;
Converts coordinates into geographic description through reverse geocoding. This API uses a promise to return the result.
......@@ -911,6 +883,7 @@ Converts coordinates into geographic description through reverse geocoding. This
**Example**
```js
import geolocation from '@ohos.geolocation';
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
console.log('getAddressesFromLocation: ' + JSON.stringify(data));
......@@ -920,7 +893,7 @@ Converts coordinates into geographic description through reverse geocoding. This
## geolocation.getAddressesFromLocationName
getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;) : void
getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
Converts geographic description into coordinates through geocoding. This API uses an asynchronous callback to return the result.
......@@ -938,6 +911,7 @@ Converts geographic description into coordinates through geocoding. This API use
**Example**
```js
import geolocation from '@ohos.geolocation';
var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => {
if (err) {
......@@ -952,7 +926,7 @@ Converts geographic description into coordinates through geocoding. This API use
## geolocation.getAddressesFromLocationName
getAddressesFromLocationName(request: GeoCodeRequest) : Promise&lt;Array&lt;GeoAddress&gt;&gt;
getAddressesFromLocationName(request: GeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;
Converts geographic description into coordinates through geocoding. This API uses a promise to return the result.
......@@ -975,6 +949,7 @@ Converts geographic description into coordinates through geocoding. This API use
**Example**
```js
import geolocation from '@ohos.geolocation';
var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
......@@ -984,7 +959,7 @@ Converts geographic description into coordinates through geocoding. This API use
## geolocation.getCachedGnssLocationsSize<sup>8+</sup>
getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;) : void;
getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;): void;
Obtains the number of cached GNSS locations.
......@@ -1001,6 +976,7 @@ Obtains the number of cached GNSS locations.
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.getCachedGnssLocationsSize((err, size) => {
if (err) {
console.log('getCachedGnssLocationsSize: err=' + JSON.stringify(err));
......@@ -1014,7 +990,7 @@ Obtains the number of cached GNSS locations.
## geolocation.getCachedGnssLocationsSize<sup>8+</sup>
getCachedGnssLocationsSize() : Promise&lt;number&gt;;
getCachedGnssLocationsSize(): Promise&lt;number&gt;;
Obtains the number of cached GNSS locations.
......@@ -1031,6 +1007,7 @@ Obtains the number of cached GNSS locations.
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.getCachedGnssLocationsSize().then((result) => {
console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
});
......@@ -1039,7 +1016,7 @@ Obtains the number of cached GNSS locations.
## geolocation.flushCachedGnssLocations<sup>8+</sup>
flushCachedGnssLocations(callback: AsyncCallback&lt;boolean&gt;) : void;
flushCachedGnssLocations(callback: AsyncCallback&lt;boolean&gt;): void;
Obtains all cached GNSS locations and clears the GNSS cache queue.
......@@ -1056,6 +1033,7 @@ Obtains all cached GNSS locations and clears the GNSS cache queue.
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.flushCachedGnssLocations((err, result) => {
if (err) {
console.log('flushCachedGnssLocations: err=' + JSON.stringify(err));
......@@ -1069,7 +1047,7 @@ Obtains all cached GNSS locations and clears the GNSS cache queue.
## geolocation.flushCachedGnssLocations<sup>8+</sup>
flushCachedGnssLocations() : Promise&lt;boolean&gt;;
flushCachedGnssLocations(): Promise&lt;boolean&gt;;
Obtains all cached GNSS locations and clears the GNSS cache queue.
......@@ -1086,6 +1064,7 @@ Obtains all cached GNSS locations and clears the GNSS cache queue.
**Example**
```js
import geolocation from '@ohos.geolocation';
geolocation.flushCachedGnssLocations().then((result) => {
console.log('promise, flushCachedGnssLocations: ' + JSON.stringify(result));
});
......@@ -1094,7 +1073,7 @@ Obtains all cached GNSS locations and clears the GNSS cache queue.
## geolocation.sendCommand<sup>8+</sup>
sendCommand(command: LocationCommand, callback: AsyncCallback&lt;boolean&gt;) : void;
sendCommand(command: LocationCommand, callback: AsyncCallback&lt;boolean&gt;): void;
Sends an extended command to the location subsystem. This API can only be called by system applications.
......@@ -1112,6 +1091,7 @@ Sends an extended command to the location subsystem. This API can only be called
**Example**
```js
import geolocation from '@ohos.geolocation';
var requestInfo = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo, (err, result) => {
if (err) {
......@@ -1126,7 +1106,7 @@ Sends an extended command to the location subsystem. This API can only be called
## geolocation.sendCommand<sup>8+</sup>
sendCommand(command: LocationCommand) : Promise&lt;boolean&gt;;
sendCommand(command: LocationCommand): Promise&lt;boolean&gt;;
Sends an extended command to the location subsystem. This API can only be called by system applications.
......@@ -1149,6 +1129,7 @@ Sends an extended command to the location subsystem. This API can only be called
**Example**
```js
import geolocation from '@ohos.geolocation';
var requestInfo = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo).then((result) => {
console.log('promise, sendCommand: ' + JSON.stringify(result));
......@@ -1156,826 +1137,182 @@ Sends an extended command to the location subsystem. This API can only be called
```
## geolocation.isLocationPrivacyConfirmed<sup>8+</sup>
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.
## LocationRequestPriority
**System API**: This is a system API and cannot be called by third-party applications.
Sets the priority of the location request.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Default Value| Description|
| -------- | -------- | -------- |
| UNSET | 0x200 | Priority unspecified.|
| ACCURACY | 0x201 | Location accuracy.|
| LOW_POWER | 0x202 | Power efficiency.|
| FIRST_FIX | 0x203 | Fast location. Use this option if you want to obtain a location as fast as possible.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
**Example**
```js
geolocation.isLocationPrivacyConfirmed(1, (err, result) => {
if (err) {
console.log('isLocationPrivacyConfirmed: err=' + JSON.stringify(err));
}
if (result) {
console.log('isLocationPrivacyConfirmed: result=' + JSON.stringify(result));
}
});
```
## LocationRequestScenario
Sets the scenario of the location request.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
## geolocation.isLocationPrivacyConfirmed<sup>8+</sup>
| Name| Default Value| Description|
| -------- | -------- | -------- |
| UNSET | 0x300 | Scenario unspecified.|
| NAVIGATION | 0x301 | Navigation.|
| TRAJECTORY_TRACKING | 0x302 | Trajectory tracking.|
| CAR_HAILING | 0x303 | Ride hailing.|
| 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.|
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.
## GeoLocationErrorCode
**System API**: This is a system API and cannot be called by third-party applications.
Enumerates error codes of the location service.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Default Value| Description|
| -------- | -------- | -------- |
| INPUT_PARAMS_ERROR<sup>7+</sup> | 101 | Incorrect input parameters.|
| REVERSE_GEOCODE_ERROR<sup>7+</sup> | 102 | Failed to call the reverse geocoding API.|
| GEOCODE_ERROR<sup>7+</sup> | 103 | Failed to call the geocoding API.|
| LOCATOR_ERROR<sup>7+</sup> | 104 | Failed to obtain the location.|
| LOCATION_SWITCH_ERROR<sup>7+</sup> | 105 | Failed to change the location service switch.|
| LAST_KNOWN_LOCATION_ERROR<sup>7+</sup> | 106 | Failed to obtain the previous location.|
| LOCATION_REQUEST_TIMEOUT_ERROR<sup>7+</sup> | 107 | Failed to obtain the location within the specified time.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.|
**Return value**
## ReverseGeoCodeRequest
| Name| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
Defines a reverse geocoding request.
**Example**
```js
geolocation.isLocationPrivacyConfirmed(1).then((result) => {
console.log('promise, isLocationPrivacyConfirmed: ' + JSON.stringify(result));
});
```
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Geocoder
## geolocation.setLocationPrivacyConfirmStatus<sup>8+</sup>
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| locale | string | No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| latitude | number | Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude | number | Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| maxItems | number | No| Maximum number of location records to be returned.|
setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed: boolean, callback: AsyncCallback&lt;boolean&gt;) : void;
Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications.
## GeoCodeRequest
**System API**: This is a system API and cannot be called by third-party applications.
Defines a geocoding request.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
**System capability**: SystemCapability.Location.Location.Geocoder
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| locale | string | No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| description | number | Yes| Location description, for example, No. xx, xx Road, Pudong New District, Shanghai.|
| maxItems | number | No| Maximum number of location records to be returned.|
| minLatitude | number | No| Minimum latitude. This parameter is used with minLongitude, maxLatitude, and maxLongitude to specify the latitude and longitude ranges.|
| minLongitude | number | No| Minimum longitude.|
| maxLatitude | number | No| Maximum latitude.|
| maxLongitude | number | No| Maximum longitude.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.|
| isConfirmed | boolean | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
| callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the operation result.|
**Example**
```js
geolocation.setLocationPrivacyConfirmStatus(1, true, (err, result) => {
if (err) {
console.log('setLocationPrivacyConfirmStatus: err=' + JSON.stringify(err));
}
if (result) {
console.log('setLocationPrivacyConfirmStatus: result=' + JSON.stringify(result));
}
});
```
## GeoAddress
Defines a geographic location.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Geocoder
## geolocation.setLocationPrivacyConfirmStatus<sup>8+</sup>
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| latitude<sup>7+</sup> | number | No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude<sup>7+</sup> | number | No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| locale<sup>7+</sup> | string | No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| placeName<sup>7+</sup> | string | No| Landmark of the location.|
| countryCode<sup>7+</sup> | string | No| Country code.|
| countryName<sup>7+</sup> | string | No| Country name.|
| administrativeArea<sup>7+</sup> | string | No| Administrative region name.|
| subAdministrativeArea<sup>7+</sup> | string | No| Sub-administrative region name.|
| locality<sup>7+</sup> | string | No| Locality information. |
| subLocality<sup>7+</sup> | string | No| Sub-locality information. |
| roadName<sup>7+</sup> | string | No| Road name.|
| subRoadName<sup>7+</sup> | string | No| Auxiliary road information.|
| premises<sup>7+</sup> | string | No| House information.|
| postalCode<sup>7+</sup> | string | No| Postal code.|
| phoneNumber<sup>7+</sup> | string | No| Phone number.|
| addressUrl<sup>7+</sup> | string | No| Website URL.|
| descriptions<sup>7+</sup> | Array&lt;string&gt; | No| Additional description.|
| descriptionsSize<sup>7+</sup> | number | No| Total number of additional descriptions.|
setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolean) : Promise&lt;boolean&gt;;
Sets the user confirmation status for the privacy statement of the location service. This API can only be called by system applications.
## LocationRequest
**System API**: This is a system API and cannot be called by third-party applications.
Defines a location request.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | No| Priority of the location request.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Scenario of the location request.|
| timeInterval | number | No| Time interval at which location information is reported.|
| distanceInterval | number | No| Distance interval at which location information is reported.|
| maxAccuracy | number | No| Location accuracy.|
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | Yes| Privacy statement type, for example, privacy statement displayed in the startup wizard or privacy statement displayed when enabling the location service.|
| isConfirmed | boolean | Yes| Callback used to return the result, which indicates whether the user agrees with the privacy statement.|
**Return value**
## CurrentLocationRequest
| Name| Description|
| -------- | -------- |
| Promise&lt;boolean&gt; | Callback used to return the operation result.|
Defines the current location request.
**Example**
```js
geolocation.setLocationPrivacyConfirmStatus(1, true).then((result) => {
console.log('promise, setLocationPrivacyConfirmStatus: ' + JSON.stringify(result));
});
```
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
## geolocation.getCountryCode<sup>9+</sup>
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | No| Priority of the location request.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | No| Scenario of the location request.|
| maxAccuracy | number | No| Location accuracy, in meters.|
| timeoutMs | number | No| Timeout duration, in milliseconds. The minimum value is 1000.|
getCountryCode(callback: AsyncCallback&lt;CountryCode&gt;) : void;
Query the current country code.
## SatelliteStatusInfo<sup>8+</sup>
**System capability**: SystemCapability.Location.Location.Core
Defines the satellite status information.
**Parameters**
**Permission required**: ohos.permission.LOCATION
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;CountryCode&gt; | Yes | Callback is used to receive the country code. |
**System capability**: SystemCapability.Location.Location.Gnss
**Example**:
```js
geolocation.getCountryCode((err, result) => {
if (err) {
console.log('getCountryCode: err=' + JSON.stringify(err));
}
if (result) {
console.log('getCountryCode: result=' + JSON.stringify(result));
}
});
```
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| satellitesNumber | number | Yes| Number of satellites.|
| satelliteIds | Array&lt;number&gt; | Yes| Array of satellite IDs.|
| carrierToNoiseDensitys | Array&lt;number&gt; | Yes| Carrier-to-noise density ratio, that is, **cn0**.|
| altitudes | Array&lt;number&gt; | Yes| Altitude information.|
| azimuths | Array&lt;number&gt; | Yes| Azimuth information.|
| carrierFrequencies | Array&lt;number&gt; | Yes| Carrier frequency.|
## geolocation.getCountryCode<sup>9+</sup>
## CachedGnssLocationsRequest<sup>8+</sup>
getCountryCode() : Promise&lt;CountryCode&gt;;
Represents a request for reporting cached GNSS locations.
Query the current country code.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
**Parameters**
None
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;CountryCode&gt; | return country code. |
**Example**:
```js
geolocation.getCountryCode()
.then((result) => {
console.log('promise, getCountryCode: result=' + JSON.stringify(result));
})
.catch((error) => {
console.log('promise, getCountryCode: error=' + JSON.stringify(error));
});
```
## geolocation.enableLocationMock<sup>9+</sup>
enableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback&lt;void&gt;) : void;
Enable the position simulation function of a scene, and only one scene can be enabled at the same time.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | No | Indicates under what scenario the position simulation function is enabled. |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var request = {"scenario": 0x0301};
geolocation.enableLocationMock(request, (err, result) => {
if (err) {
console.log('enableLocationMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('enableLocationMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.enableLocationMock<sup>9+</sup>
enableLocationMock(scenario?: LocationRequestScenario) : Promise&lt;void&gt;;
Enable the position simulation function of a scene, and only one scene can be enabled at the same time.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | No | Indicates which scene's position simulation function is enabled. If this parameter is not carried, it means that the position simulation function of all scenes is enabled. |
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var request = {"scenario": 0x0301};
geolocation.enableLocationMock(request)
.then((result) => {
if (result) {
console.log('promise, enableLocationMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, enableLocationMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.disableLocationMock<sup>9+</sup>
disableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback&lt;void&gt;) : void;
To disable the position simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | No | Indicates to disable the position simulation function of a scene. If this parameter is not carried, it means to disable the position simulation function of all scenes. |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var request = {"scenario": 0x0301};
geolocation.disableLocationMock(request, (err, result) => {
if (err) {
console.log('disableLocationMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('disableLocationMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.disableLocationMock<sup>9+</sup>
disableLocationMock(scenario?: LocationRequestScenario) : Promise&lt;void&gt;;
To disable the position simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | No | Indicates to disable the position simulation function of a scene. If this parameter is not carried, it means to disable the position simulation function of all scenes. |
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr, otherwise it will return an error message |
**Example**:
```js
var request = {"scenario": 0x0301};
geolocation.disableLocationMock(request)
.then((result) => {
if (result) {
console.log('promise, disableLocationMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, disableLocationMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.setMockedLocations<sup>9+</sup>
setMockedLocations(config: LocationMockConfig, callback: AsyncCallback&lt;void&gt;) : void;
Set the simulated location information, and then report the simulated location at the time interval carried in the interface.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | LocationMockConfig | Yes | Indicates the configuration parameters of location simulation, including the time interval of simulation location reporting and the array of simulation locations. |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var locations = [
{"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true}
];
var config = {"timeInterval": 5, "locations": locations};
geolocation.setMockedLocations(config, (err, data) => {
if (err) {
console.log('setMockedLocations: err=' + JSON.stringify(err));
}
if (data) {
console.log('setMockedLocations: data=' + JSON.stringify(data));
}
});
```
## geolocation.setMockedLocations<sup>9+</sup>
setMockedLocations(config: LocationMockConfig) : Promise&lt;void&gt;;
Set the simulated location information, and then report the simulated location at the time interval carried in the interface.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| config | LocationMockConfig | Yes | Indicates the configuration parameters of location simulation, including the time interval of simulation location reporting and the array of simulation locations. |
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var locations = [
{"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true}
];
var config = {"timeInterval": 5, "locations":locations};
geolocation.setMockedLocations(config)
.then((result) => {
if (result) {
console.log('promise, setMockedLocations: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, setMockedLocations: error=' + JSON.stringify(error));
}
});
```
## geolocation.enableReverseGeocodingMock<sup>9+</sup>
enableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;) : void;
Enable reverse geocoding simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
geolocation.enableReverseGeocodingMock((err, data) => {
if (err) {
console.log('enableReverseGeocodingMock: err=' + JSON.stringify(err));
}
if (data) {
console.log('enableReverseGeocodingMock: data=' + JSON.stringify(data));
}
});
```
## geolocation.enableReverseGeocodingMock<sup>9+</sup>
enableReverseGeocodingMock() : Promise&lt;void&gt;;
Enable reverse geocoding simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**:
None
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
geolocation.enableReverseGeocodingMock()
.then((result) => {
if (result) {
console.log('promise, enableReverseGeocodingMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, enableReverseGeocodingMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.disableReverseGeocodingMock<sup>9+</sup>
disableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;) : void;
Disable reverse geocoding simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**:
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message |
**Example**:
```js
geolocation.disableReverseGeocodingMock((err, result) => {
if (err) {
console.log('disableReverseGeocodingMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('disableReverseGeocodingMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.disableReverseGeocodingMock<sup>9+</sup>
disableReverseGeocodingMock() : Promise&lt;void&gt;;
Disable reverse geocoding simulation function.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**:
None
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
geolocation.disableReverseGeocodingMock()
.then((result) => {
if (result) {
console.log('promise, disableReverseGeocodingMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, disableReverseGeocodingMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.setReverseGeocodingMockInfo<sup>9+</sup>
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;, callback: AsyncCallback&lt;void&gt;) : void;
Set the configuration information of the reverse geocoding simulation function, including the corresponding relationship between location and place name. If the location information is in the configuration information during the subsequent reverse geocoding query, the corresponding place name will be returned.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;ReverseGeocodingMockInfo&gt; | Yes | An array of configuration parameters indicating the inverse geocoding simulation function. The configuration parameters of the inverse geocoding simulation function include a location and a place name. |
| callback | AsyncCallback&lt;void&gt; | Yes | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var mockInfos = [
{"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geolocation.setReverseGeocodingMockInfo(mockInfos, (err, data) => {
if (err) {
console.log('promise, setReverseGeocodingMockInfo, err:' + JSON.stringify(err));
}
if (data) {
console.log('promise, setReverseGeocodingMockInfo, data:' + JSON.stringify(data));
}
});
```
## geolocation.setReverseGeocodingMockInfo<sup>9+</sup>
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;) : Promise&lt;void&gt;;
Set the configuration information of the reverse geocoding simulation function, including the corresponding relationship between location and place name. If the location information is in the configuration information during the subsequent reverse geocoding query, the corresponding place name will be returned.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;ReverseGeocodingMockInfo&gt; | Yes | An array of configuration parameters indicating the inverse geocoding simulation function. The configuration parameters of the inverse geocoding simulation function include a location and a place name. |
**Return value**
| Name| Description|
| -------- | -------- |
| Promise&lt;void&gt; | It is used to receive the execution result. If the execution is successful, it will return nullptr. Otherwise, it will return an error message. |
**Example**:
```js
var mockInfos = [
{"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geolocation.setReverseGeocodingMockInfo(mockInfos)
.then((result) => {
if (result) {
console.log('promise, setReverseGeocodingMockInfo: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, setReverseGeocodingMockInfo: error=' + JSON.stringify(error));
}
});
```
## LocationRequestPriority
Sets the priority of the location request.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
| Name| Default Value| Description|
| -------- | -------- | -------- |
| UNSET | 0x200 | Priority unspecified.|
| ACCURACY | 0x201 | Location accuracy.|
| LOW_POWER | 0x202 | Power efficiency.|
| FIRST_FIX | 0x203 | Fast location. Use this option if you want to obtain a location as fast as possible.|
## LocationRequestScenario
Sets the scenario of the location request.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
| Name| Default Value| Description|
| -------- | -------- | -------- |
| UNSET | 0x300 | Scenario unspecified.|
| NAVIGATION | 0x301 | Navigation.|
| TRAJECTORY_TRACKING | 0x302 | Trajectory tracking.|
| CAR_HAILING | 0x303 | Ride hailing.|
| 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.|
## GeoLocationErrorCode
Enumerates error codes of the location service.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
| Name| Default Value| Description|
| -------- | -------- | -------- |
| NOT_SUPPORTED<sup>9+</sup> | 100 | Indicates that the interface function is not supported. |
| INPUT_PARAMS_ERROR<sup>7+</sup> | 101 | Incorrect input parameters.|
| REVERSE_GEOCODE_ERROR<sup>7+</sup> | 102 | Failed to call the reverse geocoding API.|
| GEOCODE_ERROR<sup>7+</sup> | 103 | Failed to call the geocoding API.|
| LOCATOR_ERROR<sup>7+</sup> | 104 | Failed to obtain the location.|
| LOCATION_SWITCH_ERROR<sup>7+</sup> | 105 | Failed to change the location service switch.|
| LAST_KNOWN_LOCATION_ERROR<sup>7+</sup> | 106 | Failed to obtain the previous location.|
| LOCATION_REQUEST_TIMEOUT_ERROR<sup>7+</sup> | 107 | Failed to obtain the location within the specified time.|
| QUERY_COUNTRY_CODE_ERROR<sup>9+</sup> | 108 | Indicates that the country code query failed. |
## ReverseGeoCodeRequest
Defines a reverse geocoding request.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Geocoder
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| locale | string | No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| latitude | number | Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude | number | Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| maxItems | number | No| Maximum number of location records to be returned.|
## GeoCodeRequest
Defines a geocoding request.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Geocoder
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| locale | string | No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| description | number | Yes| Location description, for example, No. xx, xx Road, Pudong New District, Shanghai.|
| maxItems | number | No| Maximum number of location records to be returned.|
| minLatitude | number | No| Minimum latitude. This parameter is used with minLongitude, maxLatitude, and maxLongitude to specify the latitude and longitude ranges.|
| minLongitude | number | No| Minimum longitude.|
| maxLatitude | number | No| Maximum latitude.|
| maxLongitude | number | No| Maximum longitude.|
## GeoAddress
Defines a geographic location.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Geocoder
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| latitude<sup>7+</sup> | number | No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
| longitude<sup>7+</sup> | number | No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude .|
| locale<sup>7+</sup> | string | No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| placeName<sup>7+</sup> | string | No| Landmark of the location.|
| countryCode<sup>7+</sup> | string | No| Country code.|
| countryName<sup>7+</sup> | string | No| Country name.|
| administrativeArea<sup>7+</sup> | string | No| Administrative region name.|
| subAdministrativeArea<sup>7+</sup> | string | No| Sub-administrative region name.|
| locality<sup>7+</sup> | string | No| Locality information. |
| subLocality<sup>7+</sup> | string | No| Sub-locality information. |
| roadName<sup>7+</sup> | string | No| Road name.|
| subRoadName<sup>7+</sup> | string | No| Auxiliary road information.|
| premises<sup>7+</sup> | string | No| House information.|
| postalCode<sup>7+</sup> | string | No| Postal code.|
| phoneNumber<sup>7+</sup> | string | No| Phone number.|
| addressUrl<sup>7+</sup> | string | No| Website URL.|
| descriptions<sup>7+</sup> | Array&lt;string&gt; | No| Additional description.|
| descriptionsSize<sup>7+</sup> | number | No| Total number of additional descriptions.|
| isFromMock<sup>9+</sup> | Boolean | No | Indicates whether the geographical name information comes from the reverse geocoding simulation function. |
## LocationRequest
Defines a location request.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | No| Priority of the location request.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Scenario of the location request.|
| timeInterval | number | No| Time interval at which location information is reported.|
| distanceInterval | number | No| Distance interval at which location information is reported.|
| maxAccuracy | number | No| Location accuracy.|
## CurrentLocationRequest
Defines the current location request.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Core
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | No| Priority of the location request.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | No| Scenario of the location request.|
| maxAccuracy | number | No| Location accuracy, in meters.|
| timeoutMs | number | No| Timeout duration, in milliseconds. The minimum value is 1000.|
## SatelliteStatusInfo<sup>8+</sup>
Defines the satellite status information.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Gnss
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| satellitesNumber | number | Yes| Number of satellites.|
| satelliteIds | Array&lt;number&gt; | Yes| Array of satellite IDs.|
| carrierToNoiseDensitys | Array&lt;number&gt; | Yes| Carrier-to-noise density ratio, that is, **cn0**.|
| altitudes | Array&lt;number&gt; | Yes| Altitude information.|
| azimuths | Array&lt;number&gt; | Yes| Azimuth information.|
| carrierFrequencies | Array&lt;number&gt; | Yes| Carrier frequency.|
## CachedGnssLocationsRequest<sup>8+</sup>
Represents a request for reporting cached GNSS locations.
**Permission required**: ohos.permission.LOCATION
**System capability**: SystemCapability.Location.Location.Gnss
**System capability**: SystemCapability.Location.Location.Gnss
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
......@@ -2063,58 +1400,3 @@ Defines a location.
| timeSinceBoot<sup>7+</sup> | number | Yes| Location timestamp since boot.|
| additions<sup>7+</sup> | Array&lt;string&gt; | No| Additional information.|
| additionSize<sup>7+</sup> | number | No| Number of additional descriptions.|
| isFromMock<sup>9+</sup> | Boolean | No | Indicates whether the location information comes from the location simulation function. |
## ReverseGeocodingMockInfo<sup>9+</sup>
The configuration information of the reverse geocoding simulation function includes a location information and a place name information.
**System capability**:SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| location | ReverseGeoCodeRequest | Yes | Indicates longitude and latitude information. |
| geoAddress | GeoAddress | Yes | Represents a geographic location. |
## LocationMockConfig<sup>9+</sup>
The configuration parameters of the location simulation function include the time interval of the simulation position report and the array of simulation locations.
**System capability**: SystemCapability.Location.Location.Core
**System API**: This is a system API and cannot be called by third-party applications.
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| timeInterval | number | Yes | Indicates the time interval of analog location reporting, in seconds. |
| locations | Array&lt;Location&gt; | Yes | Represents an array of mocked locations. |
## CountryCode<sup>9+</sup>
The country code information structure contains the country code string and the source information of the country code.
**System capability**: SystemCapability.Location.Location.Core
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| country | string | Yes | Represents the country code string. |
| type | CountryCodeType | Yes | Indicates the source of country code information. |
## CountryCodeType<sup>9+</sup>
Country code source type.
**System capability**: SystemCapability.Location.Location.Core
| Name| Default Value| Description|
| -------- | -------- | -------- |
| COUNTRY_CODE_FROM_LOCALE | 1 | The country code obtained from the language configuration information of the globalization module. |
| COUNTRY_CODE_FROM_SIM | 2 | The country code obtained from the SIM card. |
| COUNTRY_CODE_FROM_LOCATION | 3 | Based on the user's location information, the country code is queried through reverse geocoding. |
| COUNTRY_CODE_FROM_NETWORK | 4 | The country code obtained from the cellular network registration information. |
\ No newline at end of file
# 位置服务
位置服务提供GNSS定位、网络定位、地理编码、逆地理编码、国家码和地理围栏等基本功能。
> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:**
> 本模块首批接口从API version 9开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
## 导入模块
```ts
import geoLocationManager from '@ohos.geoLocationManager';
```
## geoLocationManager.on('countryCodeChange')
on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;): void;
订阅国家码信息变化事件。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示订阅国家码信息变化事件。 |
| callback | Callback&lt;[CountryCode](#countrycode)&gt; | 是 | 接收国家码信息上报。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301500 | Failed to query the area information. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var callback = (code) => {
console.log('countryCodeChange: ' + JSON.stringify(code));
}
geoLocationManager.on('countryCodeChange', callback);
```
## geoLocationManager.off('countryCodeChange')
off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;): void;
取消订阅国家码变化事件。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示取消订阅国家码信息变化事件。 |
| callback | Callback&lt;[CountryCode](#countrycode)&gt; | 是 | 接收国家码信息上报。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off. |
|3301500 | Failed to query the area information. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var callback = (code) => {
console.log('countryCodeChange: ' + JSON.stringify(code));
}
geoLocationManager.on('countryCodeChange', callback);
geoLocationManager.off('countryCodeChange', callback);
```
## geoLocationManager.enableLocation
enableLocation(callback: AsyncCallback&lt;void&gt;): void;
打开位置服务,使用callback回调异步返回结果。
**系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收错误码信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.enableLocation((err, data) => {
if (err) {
console.log('enableLocation: err=' + JSON.stringify(err));
}
});
```
## geoLocationManager.enableLocation
enableLocation(): Promise&lt;void&gt;
打开位置服务,使用Promise方式异步返回结果。
**系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 返回错误码信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.enableLocation().then((result) => {
console.log('promise, enableLocation succeed');
})
.catch((error) => {
console.log('promise, enableLocation: error=' + JSON.stringify(error));
});
```
## geoLocationManager.disableLocation
disableLocation(callback: AsyncCallback&lt;void&gt;): void;
关闭位置服务,使用callback回调异步返回结果。
**系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收错误码的回调。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.disableLocation((err, data) => {
if (err) {
console.log('disableLocation: err=' + JSON.stringify(err));
}
});
```
## geoLocationManager.disableLocation
disableLocation(): Promise&lt;void&gt;
关闭位置服务,使用Promise方式异步返回结果。
**系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 返回错误码。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.disableLocation().then((result) => {
console.log('promise, disableLocation succeed');
})
.catch((error) => {
console.log('promise, disableLocation: error=' + JSON.stringify(error));
});
```
## geoLocationManager.isLocationPrivacyConfirmed
isLocationPrivacyConfirmed(type : LocationPrivacyType, callback: AsyncCallback&lt;boolean&gt;): void;
查询用户是否同意定位服务隐私申明,是否同意启用定位服务。只有系统应用才能调用。
**系统API**:此接口为系统接口,三方应用不支持调用。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | [LocationPrivacyType](#locationprivacytype)| 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 表示用户是否同意定位服务隐私申明。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.isLocationPrivacyConfirmed(1, (err, result) => {
if (err) {
console.log('isLocationPrivacyConfirmed: err=' + JSON.stringify(err));
}
if (result) {
console.log('isLocationPrivacyConfirmed: result=' + JSON.stringify(result));
}
});
```
## geoLocationManager.isLocationPrivacyConfirmed
isLocationPrivacyConfirmed(type : LocationPrivacyType,): Promise&lt;boolean&gt;;
查询用户是否同意定位服务隐私申明,是否同意启用定位服务。只有系统应用才能调用。
**系统API**:此接口为系统接口,三方应用不支持调用。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | [LocationPrivacyType](#locationprivacytype) | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | 表示用户是否同意定位服务隐私申明。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.isLocationPrivacyConfirmed(1).then((result) => {
console.log('promise, isLocationPrivacyConfirmed: ' + JSON.stringify(result));
});
```
## geoLocationManager.setLocationPrivacyConfirmStatus
setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed: boolean, callback: AsyncCallback&lt;void&gt;): void;
设置用户勾选定位服务隐私申明的状态,记录用户是否同意启用定位服务。只有系统应用才能调用。
**系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | [LocationPrivacyType](#locationprivacytype) | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 接收错误码信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.setLocationPrivacyConfirmStatus(1, true, (err, result) => {
if (err) {
console.log('setLocationPrivacyConfirmStatus: err=' + JSON.stringify(err));
}
});
```
## geoLocationManager.setLocationPrivacyConfirmStatus
setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolean): Promise&lt;void&gt;;
设置用户勾选定位服务隐私申明的状态,记录用户是否同意启用定位服务。只有系统应用才能调用。
**系统API**:此接口为系统接口,三方应用不支持调用。
**需要权限**:ohos.permission.MANAGE_SECURE_SETTINGS
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | [LocationPrivacyType](#locationprivacytype) | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 接收错误码。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.setLocationPrivacyConfirmStatus(1, true).then((result) => {
console.log('promise, setLocationPrivacyConfirmStatus succeed');
})
.catch((error) => {
console.log('promise, disableLocation: error=' + JSON.stringify(error));
});
```
## geoLocationManager.getCountryCode
getCountryCode(callback: AsyncCallback&lt;CountryCode&gt;): void;
查询当前的国家码。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;[CountryCode](#countrycode)&gt; | 是 | 用来接收国家码。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301500 | Failed to query the area information.|
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.getCountryCode((err, result) => {
if (err) {
console.log('getCountryCode: err=' + JSON.stringify(err));
}
if (result) {
console.log('getCountryCode: result=' + JSON.stringify(result));
}
});
```
## geoLocationManager.getCountryCode
getCountryCode(): Promise&lt;CountryCode&gt;;
查询当前的国家码。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;[CountryCode](#countrycode)&gt; | 返回国家码。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301500 | Failed to query the area information.|
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.getCountryCode()
.then((result) => {
console.log('promise, getCountryCode: result=' + JSON.stringify(result));
})
.catch((error) => {
console.log('promise, getCountryCode: error=' + JSON.stringify(error));
});
```
## geoLocationManager.enableLocationMock
enableLocationMock(callback: AsyncCallback&lt;void&gt;): void;
使能位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off.|
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.enableLocationMock((err, result) => {
if (err) {
console.log('enableLocationMock: err=' + JSON.stringify(err));
}
});
```
## geoLocationManager.enableLocationMock
enableLocationMock(): Promise&lt;void&gt;;
使能位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off.|
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.enableLocationMock()
.then((result) => {
console.log('promise, enableLocationMock: succeed');
})
.catch((error) => {
if (error) {
console.log('promise, enableLocationMock: error=' + JSON.stringify(error));
}
});
```
## geoLocationManager.disableLocationMock
disableLocationMock(callback: AsyncCallback&lt;void&gt;): void;
去使能位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off.|
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.disableLocationMock((err, result) => {
if (err) {
console.log('disableLocationMock: err=' + JSON.stringify(err));
}
});
```
## geoLocationManager.disableLocationMock
disableLocationMock(): Promise&lt;void&gt;;
去使能位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off.|
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.disableLocationMock()
.then((result) => {
console.log('promise, disableLocationMock succeed');
})
.catch((error) => {
if (error) {
console.log('promise, disableLocationMock: error=' + JSON.stringify(error));
}
});
```
## geoLocationManager.setMockedLocations
setMockedLocations(config: LocationMockConfig, callback: AsyncCallback&lt;void&gt;): void;
设置模拟的位置信息,后面会以该接口中携带的时间间隔上报模拟位置。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| config | [LocationMockConfig](#locationmockconfig) | 是 | 指示位置模拟的配置参数,包含模拟位置上报的时间间隔和模拟位置数组。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off.|
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var locations = [
{"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true}
];
var config = {"timeInterval": 5, "locations": locations};
geoLocationManager.setMockedLocations(config, (err, data) => {
if (err) {
console.log('setMockedLocations: err=' + JSON.stringify(err));
}
});
```
## geoLocationManager.setMockedLocations
setMockedLocations(config: LocationMockConfig): Promise&lt;void&gt;;
设置模拟的位置信息,后面会以该接口中携带的时间间隔上报模拟位置。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| config | [LocationMockConfig](#locationmockconfig) | 是 | 指示位置模拟的配置参数,包含模拟位置上报的时间间隔和模拟位置数组。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
|3301100 | The location switch is off.|
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var locations = [
{"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true}
];
var config = {"timeInterval": 5, "locations":locations};
geoLocationManager.setMockedLocations(config)
.then((result) => {
console.log('promise, setMockedLocations succeed');
})
.catch((error) => {
if (error) {
console.log('promise, setMockedLocations: error=' + JSON.stringify(error));
}
});
```
## geoLocationManager.enableReverseGeocodingMock
enableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;): void;
使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.enableReverseGeocodingMock((err, data) => {
if (err) {
console.log('enableReverseGeocodingMock: err=' + JSON.stringify(err));
}
});
```
## geoLocationManager.enableReverseGeocodingMock
enableReverseGeocodingMock(): Promise&lt;void&gt;;
使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.enableReverseGeocodingMock()
.then((result) => {
console.log('promise, enableReverseGeocodingMock succeed');
})
.catch((error) => {
if (error) {
console.log('promise, enableReverseGeocodingMock: error=' + JSON.stringify(error));
}
});
```
## geoLocationManager.disableReverseGeocodingMock
disableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;): void;
去使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.disableReverseGeocodingMock((err, result) => {
if (err) {
console.log('disableReverseGeocodingMock: err=' + JSON.stringify(err));
}
});
```
## geoLocationManager.disableReverseGeocodingMock
disableReverseGeocodingMock(): Promise&lt;void&gt;;
去使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
geoLocationManager.disableReverseGeocodingMock()
.then((result) => {
console.log('promise, disableReverseGeocodingMock succeed');
})
.catch((error) => {
if (error) {
console.log('promise, disableReverseGeocodingMock: error=' + JSON.stringify(error));
}
});
```
## geoLocationManager.setReverseGeocodingMockInfo
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;, callback: AsyncCallback&lt;void&gt;): void;
设置逆地理编码模拟功能的配置信息,包含了位置和地名的对应关系,后续进行逆地理编码查询时如果位置信息位于配置信息中,就返回对应的地名。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)&gt; | 是 | 指示逆地理编码模拟功能的配置参数数组。逆地理编码模拟功能的配置参数包含了一个位置和一个地名。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var mockInfos = [
{"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geoLocationManager.setReverseGeocodingMockInfo(mockInfos, (err, data) => {
if (err) {
console.log('promise, setReverseGeocodingMockInfo, err:' + JSON.stringify(err));
}
});
```
## geoLocationManager.setReverseGeocodingMockInfo
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;): Promise&lt;void&gt;;
设置逆地理编码模拟功能的配置信息,包含了位置和地名的对应关系,后续进行逆地理编码查询时如果位置信息位于配置信息中,就返回对应的地名。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;[ReverseGeocodingMockInfo](#reversegeocodingmockinfo)&gt; | 是 | 指示逆地理编码模拟功能的配置信息数组。逆地理编码模拟功能的配置信息包含了一个位置和一个地名。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**错误码**
以下错误码的详细介绍请参见[位置服务子系统错误码](../errorcodes/errorcode-geoLocationManager.md)
| 错误码ID | 错误信息 |
| -------- | ---------------------------------------- |
|3301000 | Location service is unavailable. |
**示例**
```ts
import geoLocationManager from '@ohos.geoLocationManager';
var mockInfos = [
{"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geoLocationManager.setReverseGeocodingMockInfo(mockInfos)
.then((result) => {
console.log('promise, setReverseGeocodingMockInfo succeed');
})
.catch((error) => {
if (error) {
console.log('promise, setReverseGeocodingMockInfo: error=' + JSON.stringify(error));
}
});
```
## LocationRequestPriority
位置请求中位置信息优先级设置。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| UNSET | 0x200 | 表示未设置优先级。 |
| ACCURACY | 0x201 | 表示精度优先。 |
| LOW_POWER | 0x202 | 表示低功耗优先。 |
| FIRST_FIX | 0x203 | 表示快速获取位置优先,如果应用希望快速拿到1个位置,可以将优先级设置为该字段。 |
## LocationRequestScenario
位置请求中定位场景设置。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| UNSET | 0x300 | 表示未设置场景信息。 |
| NAVIGATION | 0x301 | 表示导航场景。 |
| TRAJECTORY_TRACKING | 0x302 | 表示运动轨迹记录场景。 |
| CAR_HAILING | 0x303 | 表示打车场景。 |
| DAILY_LIFE_SERVICE | 0x304 | 表示日常服务使用场景。 |
| NO_POWER | 0x305 | 表示无功耗功场景,这种场景下不会主动触发定位,会在其他应用定位时,才给当前应用返回位置。 |
## ReverseGeoCodeRequest
逆地理编码请求接口。
**系统能力**:SystemCapability.Location.Location.Geocoder
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| locale | string | 否 | 指定位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| latitude | number | 是 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude | number | 是 | 表示经度信息,正值表示东经,负值表示西经。 |
| maxItems | number | 否 | 指定返回位置信息的最大个数。 |
## GeoCodeRequest
地理编码请求接口。
**系统能力**:SystemCapability.Location.Location.Geocoder
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| locale | string | 否 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| description | number | 是 | 表示位置信息描述,如“上海市浦东新区xx路xx号”。 |
| maxItems | number | 否 | 表示返回位置信息的最大个数。 |
| minLatitude | number | 否 | 表示最小纬度信息,与下面三个参数一起,表示一个经纬度范围。 |
| minLongitude | number | 否 | 表示最小经度信息。 |
| maxLatitude | number | 否 | 表示最大纬度信息。 |
| maxLongitude | number | 否 | 表示最大经度信息。 |
## GeoAddress
地理编码类型。
**系统能力**:SystemCapability.Location.Location.Geocoder
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| latitude | number | 否 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude | number | 否 | 表示经度信息,正值表示东经,负值表是西经。 |
| locale | string | 否 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| placeName | string | 否 | 表示地区信息。 |
| countryCode | string | 否 | 表示国家码信息。 |
| countryName | string | 否 | 表示国家信息。 |
| administrativeArea | string | 否 | 表示省份区域信息。 |
| subAdministrativeArea | string | 否 | 表示表示子区域信息。 |
| locality | string | 否 | 表示城市信息。 |
| subLocality | string | 否 | 表示子城市信息。 |
| roadName | string | 否 | 表示路名信息。 |
| subRoadName | string | 否 | 表示子路名信息。 |
| premises | string | 否 | 表示门牌号信息。 |
| postalCode | string | 否 | 表示邮政编码信息。 |
| phoneNumber | string | 否 | 表示联系方式信息。 |
| addressUrl | string | 否 | 表示位置信息附件的网址信息。 |
| descriptions | Array&lt;string&gt; | 否 | 表示附加的描述信息。 |
| descriptionsSize | number | 否 | 表示附加的描述信息数量。 |
| isFromMock | Boolean | 否 | 表示地名信息是否来自于逆地理编码模拟功能。 |
## LocationRequest
位置信息请求类型。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | 否 | 表示优先级信息。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 是 | 表示场景信息。 |
| timeInterval | number | 否 | 表示上报位置信息的时间间隔。 |
| distanceInterval | number | 否 | 表示上报位置信息的距离间隔。 |
| maxAccuracy | number | 否 | 表示精度信息。仅在精确位置功能场景下有效,模糊位置功能生效场景下该字段无意义。 |
## CurrentLocationRequest
当前位置信息请求类型。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | 否 | 表示优先级信息。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 否 | 表示场景信息。 |
| maxAccuracy | number | 否 | 表示精度信息,单位是米。仅在精确位置功能场景下有效,模糊位置功能生效场景下该字段无意义。 |
| timeoutMs | number | 否 | 表示超时时间,单位是毫秒,最小为1000毫秒。 |
## SatelliteStatusInfo
卫星状态信息。
**系统能力**:SystemCapability.Location.Location.Gnss
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| satellitesNumber | number | 是 | 表示卫星个数。 |
| satelliteIds | Array&lt;number&gt; | 是 | 表示每个卫星的ID,数组类型。 |
| carrierToNoiseDensitys | Array&lt;number&gt; | 是 | 表示载波噪声功率谱密度比,即cn0。 |
| altitudes | Array&lt;number&gt; | 是 | 表示高程信息。 |
| azimuths | Array&lt;number&gt; | 是 | 表示方位角。 |
| carrierFrequencies | Array&lt;number&gt; | 是 | 表示载波频率。 |
## CachedGnssLocationsRequest
请求订阅GNSS缓存位置上报功能接口的配置参数。
**系统能力**:SystemCapability.Location.Location.Gnss
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| reportingPeriodSec | number | 是 | 表示GNSS缓存位置上报的周期,单位是毫秒。 |
| wakeUpCacheQueueFull | boolean | 是 | true表示GNSS芯片底层缓存队列满之后会主动唤醒AP芯片,并把缓存位置上报给应用。<br/>false表示GNSS芯片底层缓存队列满之后不会主动唤醒AP芯片,会把缓存位置直接丢弃。 |
## Geofence
GNSS围栏的配置参数。目前只支持圆形围栏。
**系统能力**:SystemCapability.Location.Location.Geofence
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| latitude | number | 是 | 表示纬度。 |
| longitude | number | 是 | 表示经度。 |
| radius | number | 是 | 表示圆形围栏的半径。 |
| expiration | number | 是 | 围栏存活的时间,单位是毫秒。 |
## GeofenceRequest
请求添加GNSS围栏消息中携带的参数,包括定位优先级、定位场景和围栏信息。
**系统能力**:SystemCapability.Location.Location.Geofence
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | 是 | 表示位置信息优先级。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 是 | 表示定位场景。 |
| geofence | [Geofence](#geofence) | 是 | 表示围栏信息。 |
## LocationPrivacyType
定位服务隐私协议类型。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| OTHERS | 0 | 其他场景。 |
| STARTUP | 1 | 开机向导场景下的隐私协议。 |
| CORE_LOCATION | 2 | 开启网络定位时弹出的隐私协议。 |
## LocationCommand
扩展命令结构体。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 是 | 表示定位场景。 |
| command | string | 是 | 扩展命令字符串。 |
## Location
位置信息类型。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| latitude | number | 是 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude | number | 是 | 表示经度信息,正值表示东经,负值表是西经。 |
| altitude | number | 是 | 表示高度信息,单位米。 |
| accuracy | number | 是 | 表示精度信息,单位米。 |
| speed | number | 是 | 表示速度信息,单位米每秒。 |
| timeStamp | number | 是 | 表示位置时间戳,UTC格式。 |
| direction | number | 是 | 表示航向信息。 |
| timeSinceBoot | number | 是 | 表示位置时间戳,开机时间格式。 |
| additions | Array&lt;string&gt; | 否 | 附加信息。 |
| additionSize | number | 否 | 附加信息数量。 |
| isFromMock | Boolean | 否 | 表示位置信息是否来自于位置模拟功能。 |
## ReverseGeocodingMockInfo
逆地理编码模拟功能的配置信息,包含一个位置信息和一个地名信息。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| location | [ReverseGeoCodeRequest](#reversegeocoderequest) | 是 | 表示经纬度信息。 |
| geoAddress | [GeoAddress](#geoaddress) | 是 | 表示地名信息。 |
## LocationMockConfig
位置模拟功能的配置参数,包含了模拟位置上报的时间间隔和模拟位置数组。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| timeInterval | number | 是 | 表示模拟位置上报的时间间隔,单位是秒。 |
| locations | Array&lt;Location&gt; | 是 | 表示模拟位置数组。 |
## CountryCode
国家码信息结构体,包含国家码字符串和国家码的来源信息。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| country | string | 是 | 表示国家码字符串。 |
| type | [CountryCodeType](#countrycodetype)| 是 | 表示国家码信息来源。 |
## CountryCodeType
国家码来源类型。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| COUNTRY_CODE_FROM_LOCALE | 1 | 从全球化模块的语言配置信息中获取到的国家码。 |
| COUNTRY_CODE_FROM_SIM | 2 | 从SIM卡中获取到的国家码。 |
| COUNTRY_CODE_FROM_LOCATION | 3 | 基于用户的位置信息,通过逆地理编码查询到的国家码。 |
| COUNTRY_CODE_FROM_NETWORK | 4 | 从蜂窝网络注册信息中获取到的国家码。 |
\ No newline at end of file
......@@ -8,15 +8,15 @@
## 导入模块
```js
```ts
import geolocation from '@ohos.geolocation';
```
## geolocation.on('locationChange')
on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Location&gt;) : void
on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Location&gt;): void
开启位置变化订阅,并发起定位请求。
开启位置变化订阅,并发起定位请求。定位结果按照[LocationRequest](#locationrequest)的属性进行上报,
**需要权限**:ohos.permission.LOCATION
......@@ -27,14 +27,15 @@ on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Locat
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“locationChange”,表示位置变化。 |
| request | LocationRequest | 是 | 设置位置请求参数。 |
| request | [LocationRequest](#locationrequest) | 是 | 设置位置请求参数。 |
| callback | Callback&lt;[Location](#location)&gt; | 是 | 接收位置变化状态变化监听。 |
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
......@@ -45,7 +46,7 @@ on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Locat
## geolocation.off('locationChange')
off(type: 'locationChange', callback?: Callback&lt;Location&gt;) : void
off(type: 'locationChange', callback?: Callback&lt;Location&gt;): void
关闭位置变化订阅,并删除对应的定位请求。
......@@ -63,7 +64,8 @@ off(type: 'locationChange', callback?: Callback&lt;Location&gt;) : void
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
var locationChange = (location) => {
console.log('locationChanger: data: ' + JSON.stringify(location));
......@@ -75,7 +77,7 @@ off(type: 'locationChange', callback?: Callback&lt;Location&gt;) : void
## geolocation.on('locationServiceState')
on(type: 'locationServiceState', callback: Callback&lt;boolean&gt;) : void
on(type: 'locationServiceState', callback: Callback&lt;boolean&gt;): void
订阅位置服务状态变化。
......@@ -93,7 +95,8 @@ on(type: 'locationServiceState', callback: Callback&lt;boolean&gt;) : void
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var locationServiceState = (state) => {
console.log('locationServiceState: ' + JSON.stringify(state));
}
......@@ -103,7 +106,7 @@ on(type: 'locationServiceState', callback: Callback&lt;boolean&gt;) : void
## geolocation.off('locationServiceState')
off(type: 'locationServiceState', callback?: Callback&lt;boolean&gt;) : void;
off(type: 'locationServiceState', callback?: Callback&lt;boolean&gt;): void;
取消订阅位置服务状态变化。
......@@ -121,7 +124,8 @@ off(type: 'locationServiceState', callback?: Callback&lt;boolean&gt;) : void;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var locationServiceState = (state) => {
console.log('locationServiceState: state: ' + JSON.stringify(state));
}
......@@ -132,7 +136,7 @@ off(type: 'locationServiceState', callback?: Callback&lt;boolean&gt;) : void;
## geolocation.on('cachedGnssLocationsReporting')<sup>8+</sup>
on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, callback: Callback&lt;Array&lt;Location&gt;&gt;) : void;
on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, callback: Callback&lt;Array&lt;Location&gt;&gt;): void;
订阅缓存GNSS定位结果上报事件。
......@@ -145,13 +149,14 @@ on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, ca
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“cachedGnssLocationsReporting”,表示GNSS缓存定位结果上报。 |
| request | CachedGnssLocationsRequest | 是 | GNSS缓存功能配置参数 |
| request | [CachedGnssLocationsRequest](#cachedgnsslocationsrequest) | 是 | GNSS缓存功能配置参数 |
| callback | Callback&lt;boolean&gt; | 是 | 接收GNSS缓存位置上报。 |
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var cachedLocationsCb = (locations) => {
console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
}
......@@ -162,7 +167,7 @@ on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, ca
## geolocation.off('cachedGnssLocationsReporting')<sup>8+</sup>
off(type: 'cachedGnssLocationsReporting', callback?: Callback&lt;Array&lt;Location&gt;&gt;) : void;
off(type: 'cachedGnssLocationsReporting', callback?: Callback&lt;Array&lt;Location&gt;&gt;): void;
取消订阅缓存GNSS定位结果上报事件。
......@@ -180,7 +185,8 @@ off(type: 'cachedGnssLocationsReporting', callback?: Callback&lt;Array&lt;Locati
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var cachedLocationsCb = (locations) => {
console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
}
......@@ -192,7 +198,7 @@ off(type: 'cachedGnssLocationsReporting', callback?: Callback&lt;Array&lt;Locati
## geolocation.on('gnssStatusChange')<sup>8+</sup>
on(type: 'gnssStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;) : void;
on(type: 'gnssStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;): void;
订阅GNSS卫星状态信息上报事件。
......@@ -205,12 +211,13 @@ on(type: 'gnssStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;) : vo
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“gnssStatusChange”,表示订阅GNSS卫星状态信息上报。 |
| callback | Callback&lt;SatelliteStatusInfo&gt; | 是 | 接收GNSS卫星状态信息上报。 |
| callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | 是 | 接收GNSS卫星状态信息上报。 |
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var gnssStatusCb = (satelliteStatusInfo) => {
console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
......@@ -220,7 +227,7 @@ on(type: 'gnssStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;) : vo
## geolocation.off('gnssStatusChange')<sup>8+</sup>
off(type: 'gnssStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;) : void;
off(type: 'gnssStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;): void;
取消订阅GNSS卫星状态信息上报事件。
......@@ -233,11 +240,12 @@ off(type: 'gnssStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;) :
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“gnssStatusChange”,表示订阅GNSS卫星状态信息上报。 |
| callback | Callback&lt;SatelliteStatusInfo&gt; | 否 | 接收GNSS卫星状态信息上报。 |
| callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfo)&gt; | 否 | 接收GNSS卫星状态信息上报。 |
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var gnssStatusCb = (satelliteStatusInfo) => {
console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
}
......@@ -248,7 +256,7 @@ off(type: 'gnssStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;) :
## geolocation.on('nmeaMessageChange')<sup>8+</sup>
on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;) : void;
on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;): void;
订阅GNSS NMEA信息上报事件。
......@@ -266,7 +274,8 @@ on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;) : void;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var nmeaCb = (str) => {
console.log('nmeaMessageChange: ' + JSON.stringify(str));
}
......@@ -276,7 +285,7 @@ on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;) : void;
## geolocation.off('nmeaMessageChange')<sup>8+</sup>
off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;) : void;
off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;): void;
取消订阅GNSS NMEA信息上报事件。
......@@ -294,7 +303,8 @@ off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;) : void;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var nmeaCb = (str) => {
console.log('nmeaMessageChange: ' + JSON.stringify(str));
}
......@@ -305,7 +315,7 @@ off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;) : void;
## geolocation.on('fenceStatusChange')<sup>8+</sup>
on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void;
on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
添加一个围栏,并订阅地理围栏事件。
......@@ -318,13 +328,13 @@ on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“fenceStatusChange”,表示订阅围栏事件上报。 |
| request | GeofenceRequest | 是 | 围栏的配置参数。 |
| request | [GeofenceRequest](#geofencerequest) | 是 | 围栏的配置参数。 |
| want | WantAgent | 是 | 用于接收地理围栏事件上报(进出围栏)。 |
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
import wantAgent from '@ohos.wantAgent';
......@@ -332,13 +342,13 @@ on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void;
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility"
abilityName: "com.example.myapplication.MainAbility",
action: "action1",
}
],
operationType: wantAgent.OperationType.START_ABILITY,
requestCode: 0,
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG],
};
wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
......@@ -350,7 +360,7 @@ on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void;
## geolocation.off('fenceStatusChange')<sup>8+</sup>
off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void;
off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
删除一个围栏,并取消订阅该围栏事件。
......@@ -363,12 +373,12 @@ off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“fenceStatusChange”,表示订阅围栏事件上报。 |
| request | GeofenceRequest | 是 | 围栏的配置参数。 |
| request | [GeofenceRequest](#geofencerequest) | 是 | 围栏的配置参数。 |
| want | WantAgent | 是 | 用于接收地理围栏事件上报(进出围栏)。 |
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
import wantAgent from '@ohos.wantAgent';
......@@ -376,7 +386,7 @@ off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void
wants: [
{
bundleName: "com.example.myapplication",
abilityName: "com.example.myapplication.MainAbility"
abilityName: "com.example.myapplication.MainAbility",
action: "action1",
}
],
......@@ -393,62 +403,9 @@ off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent) : void
```
## geolocation.on('countryCodeChange')<sup>9+</sup>
on(type: 'countryCodeChange', callback: Callback&lt;CountryCode&gt;) : void;
订阅国家码信息上报事件。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示订阅国家码信息上报。 |
| callback | Callback&lt;CountryCode&gt; | 是 | 接收国家码信息上报。 |
**示例**
```js
var callback = (code) => {
console.log('countryCodeChange: ' + JSON.stringify(code));
}
geolocation.on('countryCodeChange', callback);
```
## geolocation.off('countryCodeChange')<sup>9+</sup>
off(type: 'countryCodeChange', callback?: Callback&lt;CountryCode&gt;) : void;
取消订阅国家码上报事件。
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | string | 是 | 设置事件类型。type为“countryCodeChange”,表示取消订阅国家码信息上报。 |
| callback | Callback&lt;CountryCode&gt; | 是 | 接收国家码信息上报。 |
**示例**
```js
var callback = (code) => {
console.log('countryCodeChange: ' + JSON.stringify(code));
}
geolocation.on('countryCodeChange', callback);
geolocation.off('countryCodeChange', callback);
```
## geolocation.getCurrentLocation
getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;Location&gt;) : void
getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;Location&gt;): void
获取当前位置,使用callback回调异步返回结果。
......@@ -466,7 +423,8 @@ getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;L
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
var locationChange = (err, location) => {
if (err) {
......@@ -483,7 +441,7 @@ getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;L
## geolocation.getCurrentLocation
getCurrentLocation(request?: CurrentLocationRequest) : Promise&lt;Location&gt;
getCurrentLocation(request?: CurrentLocationRequest): Promise&lt;Location&gt;
获取当前位置,使用Promise方式异步返回结果。
......@@ -507,7 +465,8 @@ getCurrentLocation(request?: CurrentLocationRequest) : Promise&lt;Location&gt;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
geolocation.getCurrentLocation(requestInfo).then((result) => {
console.log('current location: ' + JSON.stringify(result));
......@@ -517,7 +476,7 @@ getCurrentLocation(request?: CurrentLocationRequest) : Promise&lt;Location&gt;
## geolocation.getLastLocation
getLastLocation(callback: AsyncCallback&lt;Location&gt;) : void
getLastLocation(callback: AsyncCallback&lt;Location&gt;): void
获取上一次位置,使用callback回调异步返回结果。
......@@ -534,7 +493,8 @@ getLastLocation(callback: AsyncCallback&lt;Location&gt;) : void
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.getLastLocation((err, data) => {
if (err) {
console.log('getLastLocation: err=' + JSON.stringify(err));
......@@ -548,7 +508,7 @@ getLastLocation(callback: AsyncCallback&lt;Location&gt;) : void
## geolocation.getLastLocation
getLastLocation() : Promise&lt;Location&gt;
getLastLocation(): Promise&lt;Location&gt;
获取上一次位置,使用Promise方式异步返回结果。
......@@ -565,7 +525,8 @@ getLastLocation() : Promise&lt;Location&gt;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.getLastLocation().then((result) => {
console.log('getLastLocation: result: ' + JSON.stringify(result));
});
......@@ -574,7 +535,7 @@ getLastLocation() : Promise&lt;Location&gt;
## geolocation.isLocationEnabled
isLocationEnabled(callback: AsyncCallback&lt;boolean&gt;) : void
isLocationEnabled(callback: AsyncCallback&lt;boolean&gt;): void
判断位置服务是否已经打开,使用callback回调异步返回结果。
......@@ -591,7 +552,8 @@ isLocationEnabled(callback: AsyncCallback&lt;boolean&gt;) : void
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.isLocationEnabled((err, data) => {
if (err) {
console.log('isLocationEnabled: err=' + JSON.stringify(err));
......@@ -605,7 +567,7 @@ isLocationEnabled(callback: AsyncCallback&lt;boolean&gt;) : void
## geolocation.isLocationEnabled
isLocationEnabled() : Promise&lt;boolean&gt;
isLocationEnabled(): Promise&lt;boolean&gt;
判断位置服务是否已经开启,使用Promise方式异步返回结果。
......@@ -621,7 +583,8 @@ isLocationEnabled() : Promise&lt;boolean&gt;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.isLocationEnabled().then((result) => {
console.log('promise, isLocationEnabled: ' + JSON.stringify(result));
});
......@@ -630,7 +593,7 @@ isLocationEnabled() : Promise&lt;boolean&gt;
## geolocation.requestEnableLocation
requestEnableLocation(callback: AsyncCallback&lt;boolean&gt;) : void
requestEnableLocation(callback: AsyncCallback&lt;boolean&gt;): void
请求打开位置服务,使用callback回调异步返回结果。
......@@ -647,7 +610,8 @@ requestEnableLocation(callback: AsyncCallback&lt;boolean&gt;) : void
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.requestEnableLocation((err, data) => {
if (err) {
console.log('requestEnableLocation: err=' + JSON.stringify(err));
......@@ -661,7 +625,7 @@ requestEnableLocation(callback: AsyncCallback&lt;boolean&gt;) : void
## geolocation.requestEnableLocation
requestEnableLocation() : Promise&lt;boolean&gt;
requestEnableLocation(): Promise&lt;boolean&gt;
请求打开位置服务,使用Promise方式异步返回结果。
......@@ -677,7 +641,8 @@ requestEnableLocation() : Promise&lt;boolean&gt;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.requestEnableLocation().then((result) => {
console.log('promise, requestEnableLocation: ' + JSON.stringify(result));
});
......@@ -686,7 +651,7 @@ requestEnableLocation() : Promise&lt;boolean&gt;
## geolocation.enableLocation
enableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
enableLocation(callback: AsyncCallback&lt;boolean&gt;): void;
打开位置服务,使用callback回调异步返回结果。
......@@ -704,7 +669,8 @@ enableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.enableLocation((err, data) => {
if (err) {
console.log('enableLocation: err=' + JSON.stringify(err));
......@@ -718,7 +684,7 @@ enableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
## geolocation.enableLocation
enableLocation() : Promise&lt;boolean&gt;
enableLocation(): Promise&lt;boolean&gt;
打开位置服务,使用Promise方式异步返回结果。
......@@ -736,7 +702,8 @@ enableLocation() : Promise&lt;boolean&gt;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.enableLocation().then((result) => {
console.log('promise, enableLocation: ' + JSON.stringify(result));
});
......@@ -744,7 +711,7 @@ enableLocation() : Promise&lt;boolean&gt;
## geolocation.disableLocation
disableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
disableLocation(callback: AsyncCallback&lt;boolean&gt;): void;
关闭位置服务,使用callback回调异步返回结果。
......@@ -762,7 +729,8 @@ disableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.disableLocation((err, data) => {
if (err) {
console.log('disableLocation: err=' + JSON.stringify(err));
......@@ -776,7 +744,7 @@ disableLocation(callback: AsyncCallback&lt;boolean&gt;) : void;
## geolocation.disableLocation
disableLocation() : Promise&lt;boolean&gt;
disableLocation(): Promise&lt;boolean&gt;
关闭位置服务,使用Promise方式异步返回结果。
......@@ -794,7 +762,8 @@ disableLocation() : Promise&lt;boolean&gt;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.disableLocation().then((result) => {
console.log('promise, disableLocation: ' + JSON.stringify(result));
});
......@@ -802,7 +771,7 @@ disableLocation() : Promise&lt;boolean&gt;
## geolocation.isGeoServiceAvailable
isGeoServiceAvailable(callback: AsyncCallback&lt;boolean&gt;) : void
isGeoServiceAvailable(callback: AsyncCallback&lt;boolean&gt;): void
判断(逆)地理编码服务状态,使用callback回调异步返回结果。
......@@ -818,7 +787,8 @@ isGeoServiceAvailable(callback: AsyncCallback&lt;boolean&gt;) : void
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.isGeoServiceAvailable((err, data) => {
if (err) {
console.log('isGeoServiceAvailable: err=' + JSON.stringify(err));
......@@ -832,7 +802,7 @@ isGeoServiceAvailable(callback: AsyncCallback&lt;boolean&gt;) : void
## geolocation.isGeoServiceAvailable
isGeoServiceAvailable() : Promise&lt;boolean&gt;
isGeoServiceAvailable(): Promise&lt;boolean&gt;
判断(逆)地理编码服务状态,使用Promise方式异步返回结果。
......@@ -848,7 +818,8 @@ isGeoServiceAvailable() : Promise&lt;boolean&gt;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.isGeoServiceAvailable().then((result) => {
console.log('promise, isGeoServiceAvailable: ' + JSON.stringify(result));
});
......@@ -857,7 +828,7 @@ isGeoServiceAvailable() : Promise&lt;boolean&gt;
## geolocation.getAddressesFromLocation
getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;) : void
getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
调用逆地理编码服务,将坐标转换为地理描述,使用callback回调异步返回结果。
......@@ -874,7 +845,8 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
if (err) {
......@@ -889,7 +861,7 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback
## geolocation.getAddressesFromLocation
getAddressesFromLocation(request: ReverseGeoCodeRequest) : Promise&lt;Array&lt;GeoAddress&gt;&gt;;
getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;;
调用逆地理编码服务,将坐标转换为地理描述,使用Promise方式异步返回结果。
......@@ -911,7 +883,8 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest) : Promise&lt;Array&lt;G
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
console.log('getAddressesFromLocation: ' + JSON.stringify(data));
......@@ -921,7 +894,7 @@ getAddressesFromLocation(request: ReverseGeoCodeRequest) : Promise&lt;Array&lt;G
## geolocation.getAddressesFromLocationName
getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;) : void
getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
调用地理编码服务,将地理描述转换为具体坐标,使用callback回调异步返回结果。
......@@ -938,7 +911,8 @@ getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => {
if (err) {
......@@ -953,7 +927,7 @@ getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt
## geolocation.getAddressesFromLocationName
getAddressesFromLocationName(request: GeoCodeRequest) : Promise&lt;Array&lt;GeoAddress&gt;&gt;
getAddressesFromLocationName(request: GeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;
调用地理编码服务,将地理描述转换为具体坐标,使用Promise方式异步返回结果。
......@@ -975,7 +949,8 @@ getAddressesFromLocationName(request: GeoCodeRequest) : Promise&lt;Array&lt;GeoA
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var geocodeRequest = {"description": "上海市浦东新区xx路xx号", "maxItems": 1};
geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
......@@ -985,7 +960,7 @@ getAddressesFromLocationName(request: GeoCodeRequest) : Promise&lt;Array&lt;GeoA
## geolocation.getCachedGnssLocationsSize<sup>8+</sup>
getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;) : void;
getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;): void;
获取GNSS芯片缓存位置的个数。
......@@ -1001,7 +976,8 @@ getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;) : void;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.getCachedGnssLocationsSize((err, size) => {
if (err) {
console.log('getCachedGnssLocationsSize: err=' + JSON.stringify(err));
......@@ -1015,7 +991,7 @@ getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;) : void;
## geolocation.getCachedGnssLocationsSize<sup>8+</sup>
getCachedGnssLocationsSize() : Promise&lt;number&gt;;
getCachedGnssLocationsSize(): Promise&lt;number&gt;;
获取GNSS芯片缓存位置的个数。
......@@ -1031,7 +1007,8 @@ getCachedGnssLocationsSize() : Promise&lt;number&gt;;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.getCachedGnssLocationsSize().then((result) => {
console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
});
......@@ -1040,7 +1017,7 @@ getCachedGnssLocationsSize() : Promise&lt;number&gt;;
## geolocation.flushCachedGnssLocations<sup>8+</sup>
flushCachedGnssLocations(callback: AsyncCallback&lt;boolean&gt;) : void;
flushCachedGnssLocations(callback: AsyncCallback&lt;boolean&gt;): void;
读取并清空GNSS芯片所有缓存位置。
......@@ -1056,7 +1033,8 @@ flushCachedGnssLocations(callback: AsyncCallback&lt;boolean&gt;) : void;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.flushCachedGnssLocations((err, result) => {
if (err) {
console.log('flushCachedGnssLocations: err=' + JSON.stringify(err));
......@@ -1070,7 +1048,7 @@ flushCachedGnssLocations(callback: AsyncCallback&lt;boolean&gt;) : void;
## geolocation.flushCachedGnssLocations<sup>8+</sup>
flushCachedGnssLocations() : Promise&lt;boolean&gt;;
flushCachedGnssLocations(): Promise&lt;boolean&gt;;
读取并清空GNSS芯片所有缓存位置。
......@@ -1086,7 +1064,8 @@ flushCachedGnssLocations() : Promise&lt;boolean&gt;;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
geolocation.flushCachedGnssLocations().then((result) => {
console.log('promise, flushCachedGnssLocations: ' + JSON.stringify(result));
});
......@@ -1095,7 +1074,7 @@ flushCachedGnssLocations() : Promise&lt;boolean&gt;;
## geolocation.sendCommand<sup>8+</sup>
sendCommand(command: LocationCommand, callback: AsyncCallback&lt;boolean&gt;) : void;
sendCommand(command: LocationCommand, callback: AsyncCallback&lt;boolean&gt;): void;
给位置服务子系统的各个部件发送扩展命令。只有系统应用才能调用。
......@@ -1107,12 +1086,13 @@ sendCommand(command: LocationCommand, callback: AsyncCallback&lt;boolean&gt;) :
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| command | LocationCommand | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
| command | [LocationCommand](#locationcommand) | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 用来接收命令发送的结果。 |
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var requestInfo = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo, (err, result) => {
if (err) {
......@@ -1127,7 +1107,7 @@ sendCommand(command: LocationCommand, callback: AsyncCallback&lt;boolean&gt;) :
## geolocation.sendCommand<sup>8+</sup>
sendCommand(command: LocationCommand) : Promise&lt;boolean&gt;;
sendCommand(command: LocationCommand): Promise&lt;boolean&gt;;
给位置服务子系统的各个部件发送扩展命令。只有系统应用才能调用。
......@@ -1139,7 +1119,7 @@ sendCommand(command: LocationCommand) : Promise&lt;boolean&gt;;
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| command | LocationCommand | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
| command | [LocationCommand](#locationcommand) | 是 | 指定目标场景,和将要发送的命令(字符串)。 |
**返回值**
......@@ -1149,7 +1129,8 @@ sendCommand(command: LocationCommand) : Promise&lt;boolean&gt;;
**示例**
```js
```ts
import geolocation from '@ohos.geolocation';
var requestInfo = {'scenario': 0x301, 'command': "command_1"};
geolocation.sendCommand(requestInfo).then((result) => {
console.log('promise, sendCommand: ' + JSON.stringify(result));
......@@ -1157,836 +1138,193 @@ sendCommand(command: LocationCommand) : Promise&lt;boolean&gt;;
```
## geolocation.isLocationPrivacyConfirmed<sup>8+</sup>
isLocationPrivacyConfirmed(type : LocationPrivacyType, callback: AsyncCallback&lt;boolean&gt;) : void;
查询用户是否同意定位服务隐私申明,是否同意启用定位服务。只有系统应用才能调用。
## LocationRequestPriority
**系统API**:此接口为系统接口,三方应用不支持调用
位置请求中位置信息优先级设置
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| UNSET | 0x200 | 表示未设置优先级。 |
| ACCURACY | 0x201 | 表示精度优先。 |
| LOW_POWER | 0x202 | 表示低功耗优先。 |
| FIRST_FIX | 0x203 | 表示快速获取位置优先,如果应用希望快速拿到1个位置,可以将优先级设置为该字段。 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 表示用户是否同意定位服务隐私申明。 |
**示例**
```js
geolocation.isLocationPrivacyConfirmed(1, (err, result) => {
if (err) {
console.log('isLocationPrivacyConfirmed: err=' + JSON.stringify(err));
}
if (result) {
console.log('isLocationPrivacyConfirmed: result=' + JSON.stringify(result));
}
});
```
## LocationRequestScenario
位置请求中定位场景设置。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
## geolocation.isLocationPrivacyConfirmed<sup>8+</sup>
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| UNSET | 0x300 | 表示未设置场景信息。 |
| NAVIGATION | 0x301 | 表示导航场景。 |
| TRAJECTORY_TRACKING | 0x302 | 表示运动轨迹记录场景。 |
| CAR_HAILING | 0x303 | 表示打车场景。 |
| DAILY_LIFE_SERVICE | 0x304 | 表示日常服务使用场景。 |
| NO_POWER | 0x305 | 表示无功耗功场景,这种场景下不会主动触发定位,会在其他应用定位时,才给当前应用返回位置。 |
isLocationPrivacyConfirmed(type : LocationPrivacyType,) : Promise&lt;boolean&gt;;
查询用户是否同意定位服务隐私申明,是否同意启用定位服务。只有系统应用才能调用。
## GeoLocationErrorCode
**系统API**:此接口为系统接口,三方应用不支持调用
位置服务中的错误码信息
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| INPUT_PARAMS_ERROR<sup>7+</sup> | 101 | 表示输入参数错误。 |
| REVERSE_GEOCODE_ERROR<sup>7+</sup> | 102 | 表示逆地理编码接口调用失败。 |
| GEOCODE_ERROR<sup>7+</sup> | 103 | 表示地理编码接口调用失败。 |
| LOCATOR_ERROR<sup>7+</sup> | 104 | 表示定位失败。 |
| LOCATION_SWITCH_ERROR<sup>7+</sup> | 105 | 表示定位开关。 |
| LAST_KNOWN_LOCATION_ERROR<sup>7+</sup> | 106 | 表示获取上次位置失败。 |
| LOCATION_REQUEST_TIMEOUT_ERROR<sup>7+</sup> | 107 | 表示单次定位,没有在指定时间内返回位置。 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
**返回值**
## ReverseGeoCodeRequest
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | 表示用户是否同意定位服务隐私申明。 |
逆地理编码请求接口。
**示例**
```js
geolocation.isLocationPrivacyConfirmed(1).then((result) => {
console.log('promise, isLocationPrivacyConfirmed: ' + JSON.stringify(result));
});
```
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Geocoder
## geolocation.setLocationPrivacyConfirmStatus<sup>8+</sup>
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| locale | string | 否 | 指定位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| latitude | number | 是 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude | number | 是 | 表示经度信息,正值表示东经,负值表示西经。 |
| maxItems | number | 否 | 指定返回位置信息的最大个数。 |
setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed: boolean, callback: AsyncCallback&lt;boolean&gt;) : void;
设置用户勾选定位服务隐私申明的状态,记录用户是否同意启用定位服务。只有系统应用才能调用。
## GeoCodeRequest
**系统API**:此接口为系统接口,三方应用不支持调用
地理编码请求接口
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
**系统能力**:SystemCapability.Location.Location.Geocoder
**参数**
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| locale | string | 否 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| description | number | 是 | 表示位置信息描述,如“上海市浦东新区xx路xx号”。 |
| maxItems | number | 否 | 表示返回位置信息的最大个数。 |
| minLatitude | number | 否 | 表示最小纬度信息,与下面三个参数一起,表示一个经纬度范围。 |
| minLongitude | number | 否 | 表示最小经度信息。 |
| maxLatitude | number | 否 | 表示最大纬度信息。 |
| maxLongitude | number | 否 | 表示最大经度信息。 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 |
| callback | AsyncCallback&lt;boolean&gt; | 是 | 表示操作是否成功。 |
**示例**
```js
geolocation.setLocationPrivacyConfirmStatus(1, true, (err, result) => {
if (err) {
console.log('setLocationPrivacyConfirmStatus: err=' + JSON.stringify(err));
}
if (result) {
console.log('setLocationPrivacyConfirmStatus: result=' + JSON.stringify(result));
}
});
```
## GeoAddress
地理编码类型。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Geocoder
## geolocation.setLocationPrivacyConfirmStatus<sup>8+</sup>
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| latitude<sup>7+</sup> | number | 否 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude<sup>7+</sup> | number | 否 | 表示经度信息,正值表示东经,负值表是西经。 |
| locale<sup>7+</sup> | string | 否 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| placeName<sup>7+</sup> | string | 否 | 表示地区信息。 |
| countryCode<sup>7+</sup> | string | 否 | 表示国家码信息。 |
| countryName<sup>7+</sup> | string | 否 | 表示国家信息。 |
| administrativeArea<sup>7+</sup> | string | 否 | 表示省份区域信息。 |
| subAdministrativeArea<sup>7+</sup> | string | 否 | 表示表示子区域信息。 |
| locality<sup>7+</sup> | string | 否 | 表示城市信息。 |
| subLocality<sup>7+</sup> | string | 否 | 表示子城市信息。 |
| roadName<sup>7+</sup> | string | 否 | 表示路名信息。 |
| subRoadName<sup>7+</sup> | string | 否 | 表示子路名信息。 |
| premises<sup>7+</sup> | string | 否 | 表示门牌号信息。 |
| postalCode<sup>7+</sup> | string | 否 | 表示邮政编码信息。 |
| phoneNumber<sup>7+</sup> | string | 否 | 表示联系方式信息。 |
| addressUrl<sup>7+</sup> | string | 否 | 表示位置信息附件的网址信息。 |
| descriptions<sup>7+</sup> | Array&lt;string&gt; | 否 | 表示附加的描述信息。 |
| descriptionsSize<sup>7+</sup> | number | 否 | 表示附加的描述信息数量。 |
setLocationPrivacyConfirmStatus(type : LocationPrivacyType, isConfirmed : boolean) : Promise&lt;boolean&gt;;
设置用户勾选定位服务隐私申明的状态,记录用户是否同意启用定位服务。只有系统应用才能调用。
## LocationRequest
**系统API**:此接口为系统接口,三方应用不支持调用
位置信息请求类型
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
**参数**
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | 否 | 表示优先级信息。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 是 | 表示场景信息。 |
| timeInterval | number | 否 | 表示上报位置信息的时间间隔。 |
| distanceInterval | number | 否 | 表示上报位置信息的距离间隔。 |
| maxAccuracy | number | 否 | 表示精度信息。仅在精确位置功能场景下有效,模糊位置功能生效场景下该字段无意义。 |
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| type | LocationPrivacyType | 是 | 指定隐私申明场景,例如开机向导中的隐私申明、开启网络定位功能时弹出的隐私申明等。 |
| isConfirmed | boolean | 是 | 表示用户是否同意定位服务隐私申明。 |
**返回值**
## CurrentLocationRequest
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;boolean&gt; | 表示操作是否成功。 |
当前位置信息请求类型。
**示例**
```js
geolocation.setLocationPrivacyConfirmStatus(1, true).then((result) => {
console.log('promise, setLocationPrivacyConfirmStatus: ' + JSON.stringify(result));
});
```
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
## geolocation.getCountryCode<sup>9+</sup>
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | 否 | 表示优先级信息。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 否 | 表示场景信息。 |
| maxAccuracy | number | 否 | 表示精度信息,单位是米。仅在精确位置功能场景下有效,模糊位置功能生效场景下该字段无意义。 |
| timeoutMs | number | 否 | 表示超时时间,单位是毫秒,最小为1000毫秒。 |
getCountryCode(callback: AsyncCallback&lt;CountryCode&gt;) : void;
查询当前的国家码。
## SatelliteStatusInfo<sup>8+</sup>
**系统能力**:SystemCapability.Location.Location.Core
卫星状态信息。
**参数**
**需要权限**:ohos.permission.LOCATION
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;CountryCode&gt; | 是 | 用来接收国家码。 |
**系统能力**:SystemCapability.Location.Location.Gnss
**示例**
```js
geolocation.getCountryCode((err, result) => {
if (err) {
console.log('getCountryCode: err=' + JSON.stringify(err));
}
if (result) {
console.log('getCountryCode: result=' + JSON.stringify(result));
}
});
```
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| satellitesNumber | number | 是 | 表示卫星个数。 |
| satelliteIds | Array&lt;number&gt; | 是 | 表示每个卫星的ID,数组类型。 |
| carrierToNoiseDensitys | Array&lt;number&gt; | 是 | 表示载波噪声功率谱密度比,即cn0。 |
| altitudes | Array&lt;number&gt; | 是 | 表示高程信息。 |
| azimuths | Array&lt;number&gt; | 是 | 表示方位角。 |
| carrierFrequencies | Array&lt;number&gt; | 是 | 表示载波频率。 |
## geolocation.getCountryCode<sup>9+</sup>
## CachedGnssLocationsRequest<sup>8+</sup>
getCountryCode() : Promise&lt;CountryCode&gt;;
请求订阅GNSS缓存位置上报功能接口的配置参数。
查询当前的国家码。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
**系统能力**:SystemCapability.Location.Location.Gnss
**参数**
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| reportingPeriodSec | number | 是 | 表示GNSS缓存位置上报的周期,单位是毫秒。 |
| wakeUpCacheQueueFull | boolean | 是 | true表示GNSS芯片底层缓存队列满之后会主动唤醒AP芯片,并把缓存位置上报给应用。<br/>false表示GNSS芯片底层缓存队列满之后不会主动唤醒AP芯片,会把缓存位置直接丢弃。 |
**返回值**
## Geofence<sup>8+</sup>
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;CountryCode&gt; | 返回国家码。 |
**示例**
```js
geolocation.getCountryCode()
.then((result) => {
console.log('promise, getCountryCode: result=' + JSON.stringify(result));
})
.catch((error) => {
console.log('promise, getCountryCode: error=' + JSON.stringify(error));
});
```
## geolocation.enableLocationMock<sup>9+</sup>
enableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback&lt;void&gt;) : void;
使能某个场景的位置模拟功能,同一时间只能使能一个场景的位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | 否 | 指示在什么场景下使能位置模拟功能。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var request = {"scenario": 0x0301};
geolocation.enableLocationMock(request, (err, result) => {
if (err) {
console.log('enableLocationMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('enableLocationMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.enableLocationMock<sup>9+</sup>
enableLocationMock(scenario?: LocationRequestScenario) : Promise&lt;void&gt;;
使能某个场景的位置模拟功能,同一时间只能使能一个场景的位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | 否 | 指示使能什么场景的位置模拟功能。如果不携带该参数则表示使能所有场景的位置模拟功能。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var request = {"scenario": 0x0301};
geolocation.enableLocationMock(request)
.then((result) => {
if (result) {
console.log('promise, enableLocationMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, enableLocationMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.disableLocationMock<sup>9+</sup>
disableLocationMock(scenario?: LocationRequestScenario, callback: AsyncCallback&lt;void&gt;) : void;
去使能位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | 否 | 指示去使能某个场景的位置模拟功能。如果不携带该参数则表示去使能所有场景的位置模拟功能。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var request = {"scenario": 0x0301};
geolocation.disableLocationMock(request, (err, result) => {
if (err) {
console.log('disableLocationMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('disableLocationMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.disableLocationMock<sup>9+</sup>
disableLocationMock(scenario?: LocationRequestScenario) : Promise&lt;void&gt;;
去使能位置模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | 否 | 指示去使能某个场景的位置模拟功能。如果不携带该参数则表示去使能所有场景的位置模拟功能。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var request = {"scenario": 0x0301};
geolocation.disableLocationMock(request)
.then((result) => {
if (result) {
console.log('promise, disableLocationMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, disableLocationMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.setMockedLocations<sup>9+</sup>
setMockedLocations(config: LocationMockConfig, callback: AsyncCallback&lt;void&gt;) : void;
设置模拟的位置信息,后面会以该接口中携带的时间间隔上报模拟位置。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| config | LocationMockConfig | 是 | 指示位置模拟的配置参数,包含模拟位置上报的时间间隔和模拟位置数组。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var locations = [
{"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true}
];
var config = {"timeInterval": 5, "locations": locations};
geolocation.setMockedLocations(config, (err, data) => {
if (err) {
console.log('setMockedLocations: err=' + JSON.stringify(err));
}
if (data) {
console.log('setMockedLocations: data=' + JSON.stringify(data));
}
});
```
## geolocation.setMockedLocations<sup>9+</sup>
setMockedLocations(config: LocationMockConfig) : Promise&lt;void&gt;;
设置模拟的位置信息,后面会以该接口中携带的时间间隔上报模拟位置。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| config | LocationMockConfig | 是 | 指示位置模拟的配置参数,包含模拟位置上报的时间间隔和模拟位置数组。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var locations = [
{"latitude": 30.12, "longitude": 120.11, "altitude": 123, "accuracy": 1, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 1000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 31.13, "longitude": 121.11, "altitude": 123, "accuracy": 2, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 2000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 32.14, "longitude": 122.11, "altitude": 123, "accuracy": 3, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 3000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 33.15, "longitude": 123.11, "altitude": 123, "accuracy": 4, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 4000000000, "additionSize": 0, "isFromMock": true},
{"latitude": 34.16, "longitude": 124.11, "altitude": 123, "accuracy": 5, "speed": 5.2, "timeStamp": 16594326109, "direction": 123.11, "timeSinceBoot": 5000000000, "additionSize": 0, "isFromMock": true}
];
var config = {"timeInterval": 5, "locations":locations};
geolocation.setMockedLocations(config)
.then((result) => {
if (result) {
console.log('promise, setMockedLocations: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, setMockedLocations: error=' + JSON.stringify(error));
}
});
```
## geolocation.enableReverseGeocodingMock<sup>9+</sup>
enableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;) : void;
使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
geolocation.enableReverseGeocodingMock((err, data) => {
if (err) {
console.log('enableReverseGeocodingMock: err=' + JSON.stringify(err));
}
if (data) {
console.log('enableReverseGeocodingMock: data=' + JSON.stringify(data));
}
});
```
## geolocation.enableReverseGeocodingMock<sup>9+</sup>
enableReverseGeocodingMock() : Promise&lt;void&gt;;
使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
geolocation.enableReverseGeocodingMock()
.then((result) => {
if (result) {
console.log('promise, enableReverseGeocodingMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, enableReverseGeocodingMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.disableReverseGeocodingMock<sup>9+</sup>
disableReverseGeocodingMock(callback: AsyncCallback&lt;void&gt;) : void;
去使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
geolocation.disableReverseGeocodingMock((err, result) => {
if (err) {
console.log('disableReverseGeocodingMock: err=' + JSON.stringify(err));
}
if (result) {
console.log('disableReverseGeocodingMock: result=' + JSON.stringify(result));
}
});
```
## geolocation.disableReverseGeocodingMock<sup>9+</sup>
disableReverseGeocodingMock() : Promise&lt;void&gt;;
去使能逆地理编码模拟功能。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
geolocation.disableReverseGeocodingMock()
.then((result) => {
if (result) {
console.log('promise, disableReverseGeocodingMock: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, disableReverseGeocodingMock: error=' + JSON.stringify(error));
}
});
```
## geolocation.setReverseGeocodingMockInfo<sup>9+</sup>
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;, callback: AsyncCallback&lt;void&gt;) : void;
设置逆地理编码模拟功能的配置信息,包含了位置和地名的对应关系,后续进行逆地理编码查询时如果位置信息位于配置信息中,就返回对应的地名。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;ReverseGeocodingMockInfo&gt; | 是 | 指示逆地理编码模拟功能的配置参数数组。逆地理编码模拟功能的配置参数包含了一个位置和一个地名。 |
| callback | AsyncCallback&lt;void&gt; | 是 | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var mockInfos = [
{"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geolocation.setReverseGeocodingMockInfo(mockInfos, (err, data) => {
if (err) {
console.log('promise, setReverseGeocodingMockInfo, err:' + JSON.stringify(err));
}
if (data) {
console.log('promise, setReverseGeocodingMockInfo, data:' + JSON.stringify(data));
}
});
```
## geolocation.setReverseGeocodingMockInfo<sup>9+</sup>
setReverseGeocodingMockInfo(mockInfos: Array&lt;ReverseGeocodingMockInfo&gt;) : Promise&lt;void&gt;;
设置逆地理编码模拟功能的配置信息,包含了位置和地名的对应关系,后续进行逆地理编码查询时如果位置信息位于配置信息中,就返回对应的地名。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
**参数**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| mockInfos | Array&lt;ReverseGeocodingMockInfo&gt; | 是 | 指示逆地理编码模拟功能的配置信息数组。逆地理编码模拟功能的配置信息包含了一个位置和一个地名。 |
**返回值**
| 参数名 | 说明 |
| -------- | -------- |
| Promise&lt;void&gt; | 用来接收执行结果,如果执行成功就返回nullptr,否则就返回错误信息。 |
**示例**
```js
var mockInfos = [
{"location": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 30.12, "longitude": 120.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 31.12, "longitude": 121.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 32.12, "longitude": 122.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 33.12, "longitude": 123.11, "maxItems": 1, "isFromMock": true}},
{"location": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1}, "geoAddress": {"locale": "zh", "latitude": 34.12, "longitude": 124.11, "maxItems": 1, "isFromMock": true}},
];
geolocation.setReverseGeocodingMockInfo(mockInfos)
.then((result) => {
if (result) {
console.log('promise, setReverseGeocodingMockInfo: result=' + JSON.stringify(result));
}
})
.catch((error) => {
if (error) {
console.log('promise, setReverseGeocodingMockInfo: error=' + JSON.stringify(error));
}
});
```
## LocationRequestPriority
位置请求中位置信息优先级设置。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| UNSET | 0x200 | 表示未设置优先级。 |
| ACCURACY | 0x201 | 表示精度优先。 |
| LOW_POWER | 0x202 | 表示低功耗优先。 |
| FIRST_FIX | 0x203 | 表示快速获取位置优先,如果应用希望快速拿到1个位置,可以将优先级设置为该字段。 |
## LocationRequestScenario
位置请求中定位场景设置。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| UNSET | 0x300 | 表示未设置场景信息。 |
| NAVIGATION | 0x301 | 表示导航场景。 |
| TRAJECTORY_TRACKING | 0x302 | 表示运动轨迹记录场景。 |
| CAR_HAILING | 0x303 | 表示打车场景。 |
| DAILY_LIFE_SERVICE | 0x304 | 表示日常服务使用场景。 |
| NO_POWER | 0x305 | 表示无功耗功场景,这种场景下不会主动触发定位,会在其他应用定位时,才给当前应用返回位置。 |
## GeoLocationErrorCode
位置服务中的错误码信息。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| NOT_SUPPORTED<sup>9+</sup> | 100 | 表示该接口功能不支持。 |
| INPUT_PARAMS_ERROR<sup>7+</sup> | 101 | 表示输入参数错误。 |
| REVERSE_GEOCODE_ERROR<sup>7+</sup> | 102 | 表示逆地理编码接口调用失败。 |
| GEOCODE_ERROR<sup>7+</sup> | 103 | 表示地理编码接口调用失败。 |
| LOCATOR_ERROR<sup>7+</sup> | 104 | 表示定位失败。 |
| LOCATION_SWITCH_ERROR<sup>7+</sup> | 105 | 表示定位开关。 |
| LAST_KNOWN_LOCATION_ERROR<sup>7+</sup> | 106 | 表示获取上次位置失败。 |
| LOCATION_REQUEST_TIMEOUT_ERROR<sup>7+</sup> | 107 | 表示单次定位,没有在指定时间内返回位置。 |
| QUERY_COUNTRY_CODE_ERROR<sup>9+</sup> | 108 | 表示国家码查询失败。 |
## ReverseGeoCodeRequest
逆地理编码请求接口。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Geocoder
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| locale | string | 否 | 指定位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| latitude | number | 是 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude | number | 是 | 表示经度信息,正值表示东经,负值表示西经。 |
| maxItems | number | 否 | 指定返回位置信息的最大个数。 |
## GeoCodeRequest
地理编码请求接口。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Geocoder
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| locale | string | 否 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| description | number | 是 | 表示位置信息描述,如“上海市浦东新区xx路xx号”。 |
| maxItems | number | 否 | 表示返回位置信息的最大个数。 |
| minLatitude | number | 否 | 表示最小纬度信息,与下面三个参数一起,表示一个经纬度范围。 |
| minLongitude | number | 否 | 表示最小经度信息。 |
| maxLatitude | number | 否 | 表示最大纬度信息。 |
| maxLongitude | number | 否 | 表示最大经度信息。 |
## GeoAddress
地理编码类型。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Geocoder
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| latitude<sup>7+</sup> | number | 否 | 表示纬度信息,正值表示北纬,负值表示南纬。 |
| longitude<sup>7+</sup> | number | 否 | 表示经度信息,正值表示东经,负值表是西经。 |
| locale<sup>7+</sup> | string | 否 | 表示位置描述信息的语言,“zh”代表中文,“en”代表英文。 |
| placeName<sup>7+</sup> | string | 否 | 表示地区信息。 |
| countryCode<sup>7+</sup> | string | 否 | 表示国家码信息。 |
| countryName<sup>7+</sup> | string | 否 | 表示国家信息。 |
| administrativeArea<sup>7+</sup> | string | 否 | 表示省份区域信息。 |
| subAdministrativeArea<sup>7+</sup> | string | 否 | 表示表示子区域信息。 |
| locality<sup>7+</sup> | string | 否 | 表示城市信息。 |
| subLocality<sup>7+</sup> | string | 否 | 表示子城市信息。 |
| roadName<sup>7+</sup> | string | 否 | 表示路名信息。 |
| subRoadName<sup>7+</sup> | string | 否 | 表示子路名信息。 |
| premises<sup>7+</sup> | string | 否 | 表示门牌号信息。 |
| postalCode<sup>7+</sup> | string | 否 | 表示邮政编码信息。 |
| phoneNumber<sup>7+</sup> | string | 否 | 表示联系方式信息。 |
| addressUrl<sup>7+</sup> | string | 否 | 表示位置信息附件的网址信息。 |
| descriptions<sup>7+</sup> | Array&lt;string&gt; | 否 | 表示附加的描述信息。 |
| descriptionsSize<sup>7+</sup> | number | 否 | 表示附加的描述信息数量。 |
| isFromMock<sup>9+</sup> | Boolean | 否 | 表示地名信息是否来自于逆地理编码模拟功能。 |
## LocationRequest
位置信息请求类型。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | 否 | 表示优先级信息。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 是 | 表示场景信息。 |
| timeInterval | number | 否 | 表示上报位置信息的时间间隔。 |
| distanceInterval | number | 否 | 表示上报位置信息的距离间隔。 |
| maxAccuracy | number | 否 | 表示精度信息。 |
## CurrentLocationRequest
当前位置信息请求类型。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | 否 | 表示优先级信息。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 否 | 表示场景信息。 |
| maxAccuracy | number | 否 | 表示精度信息,单位是米。 |
| timeoutMs | number | 否 | 表示超时时间,单位是毫秒,最小为1000毫秒。 |
## SatelliteStatusInfo<sup>8+</sup>
卫星状态信息。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Gnss
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| satellitesNumber | number | 是 | 表示卫星个数。 |
| satelliteIds | Array&lt;number&gt; | 是 | 表示每个卫星的ID,数组类型。 |
| carrierToNoiseDensitys | Array&lt;number&gt; | 是 | 表示载波噪声功率谱密度比,即cn0。 |
| altitudes | Array&lt;number&gt; | 是 | 表示高程信息。 |
| azimuths | Array&lt;number&gt; | 是 | 表示方位角。 |
| carrierFrequencies | Array&lt;number&gt; | 是 | 表示载波频率。 |
## CachedGnssLocationsRequest<sup>8+</sup>
请求订阅GNSS缓存位置上报功能接口的配置参数。
**需要权限**:ohos.permission.LOCATION
**系统能力**:SystemCapability.Location.Location.Gnss
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| reportingPeriodSec | number | 是 | 表示GNSS缓存位置上报的周期,单位是毫秒。 |
| wakeUpCacheQueueFull | boolean | 是 | true表示GNSS芯片底层缓存队列满之后会主动唤醒AP芯片,并把缓存位置上报给应用。<br/>false表示GNSS芯片底层缓存队列满之后不会主动唤醒AP芯片,会把缓存位置直接丢弃。 |
## Geofence<sup>8+</sup>
GNSS围栏的配置参数。目前只支持圆形围栏。
GNSS围栏的配置参数。目前只支持圆形围栏。
**需要权限**:ohos.permission.LOCATION
......@@ -2010,9 +1348,9 @@ GNSS围栏的配置参数。目前只支持圆形围栏。
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| priority | LocationRequestPriority | 是 | 表示位置信息优先级。 |
| scenario | LocationRequestScenario | 是 | 表示定位场景。 |
| geofence | Geofence | 是 | 表示围栏信息。 |
| priority | [LocationRequestPriority](#locationrequestpriority) | 是 | 表示位置信息优先级。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 是 | 表示定位场景。 |
| geofence | [Geofence](#geofence)| 是 | 表示围栏信息。 |
## LocationPrivacyType<sup>8+</sup>
......@@ -2040,7 +1378,7 @@ GNSS围栏的配置参数。目前只支持圆形围栏。
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| scenario | LocationRequestScenario | 是 | 表示定位场景。 |
| scenario | [LocationRequestScenario](#locationrequestscenario) | 是 | 表示定位场景。 |
| command | string | 是 | 扩展命令字符串。 |
......@@ -2063,59 +1401,4 @@ GNSS围栏的配置参数。目前只支持圆形围栏。
| direction<sup>7+</sup> | number | 是 | 表示航向信息。 |
| timeSinceBoot<sup>7+</sup> | number | 是 | 表示位置时间戳,开机时间格式。 |
| additions<sup>7+</sup> | Array&lt;string&gt; | 否 | 附加信息。 |
| additionSize<sup>7+</sup> | number | 否 | 附加信息数量。 |
| isFromMock<sup>9+</sup> | Boolean | 否 | 表示位置信息是否来自于位置模拟功能。 |
## ReverseGeocodingMockInfo<sup>9+</sup>
逆地理编码模拟功能的配置信息,包含一个位置信息和一个地名信息。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| location | ReverseGeoCodeRequest | 是 | 表示经纬度信息。 |
| geoAddress | GeoAddress | 是 | 表示地名信息。 |
## LocationMockConfig<sup>9+</sup>
位置模拟功能的配置参数,包含了模拟位置上报的时间间隔和模拟位置数组。
**系统能力**:SystemCapability.Location.Location.Core
**系统API**:此接口为系统接口,三方应用不支持调用。
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| timeInterval | number | 是 | 表示模拟位置上报的时间间隔,单位是秒。 |
| locations | Array&lt;Location&gt; | 是 | 表示模拟位置数组。 |
## CountryCode<sup>9+</sup>
国家码信息结构体,包含国家码字符串和国家码的来源信息。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 参数类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| country | string | 是 | 表示国家码字符串。 |
| type | CountryCodeType | 是 | 表示国家码信息来源。 |
## CountryCodeType<sup>9+</sup>
国家码来源类型。
**系统能力**:SystemCapability.Location.Location.Core
| 名称 | 默认值 | 说明 |
| -------- | -------- | -------- |
| COUNTRY_CODE_FROM_LOCALE | 1 | 从全球化模块的语言配置信息中获取到的国家码。 |
| COUNTRY_CODE_FROM_SIM | 2 | 从SIM卡中获取到的国家码。 |
| COUNTRY_CODE_FROM_LOCATION | 3 | 基于用户的位置信息,通过逆地理编码查询到的国家码。 |
| COUNTRY_CODE_FROM_NETWORK | 4 | 从蜂窝网络注册信息中获取到的国家码。 |
\ No newline at end of file
| additionSize<sup>7+</sup> | number | 否 | 附加信息数量。 |
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册