js-apis-geolocation.md 63.1 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.geolocation (Geolocation)
Z
zengyawen 已提交
2

S
shawn_he 已提交
3
The **geolocation** module provides a wide array of location services, including GNSS positioning, network positioning, geocoding, reverse geocoding, and geofencing.
Z
zengyawen 已提交
4

S
shawn_he 已提交
5
> **NOTE**
S
shawn_he 已提交
6
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
S
shawn_he 已提交
7
> The APIs provided by this module are no longer maintained since API version 9. You are advised to use [geoLocationManager](js-apis-geoLocationManager.md).
S
shawn_he 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21

## Applying for Permissions

Before using basic location capabilities, check whether your application has been granted the permission to access the device location information. If not, your application needs to obtain the permission from the user as described below.

The system provides the following location permissions:
- ohos.permission.LOCATION

- ohos.permission.APPROXIMATELY_LOCATION

- ohos.permission.LOCATION_IN_BACKGROUND

If your application needs to access the device location information, it must first apply for required permissions. Specifically speaking:

S
shawn_he 已提交
22
API versions earlier than 9: Apply for **ohos.permission.LOCATION**.
S
shawn_he 已提交
23

S
shawn_he 已提交
24
API version 9 and later: Apply for **ohos.permission.APPROXIMATELY_LOCATION**, or apply for **ohos.permission.APPROXIMATELY_LOCATION** and **ohos.permission.LOCATION**. Note that **ohos.permission.LOCATION** cannot be applied for separately.
S
shawn_he 已提交
25 26 27

| API Version| Location Permission| Permission Application Result| Location Accuracy|
| -------- | -------- | -------- | -------- |
S
shawn_he 已提交
28 29 30 31
| Earlier than 9| ohos.permission.LOCATION | Successful| Location accurate to meters.|
| 9 and later| ohos.permission.LOCATION | Failed| No location obtained.|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Successful| Location accurate to 5 kilometers.|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Successful| Location accurate to meters.|
S
shawn_he 已提交
32

S
shawn_he 已提交
33
If your application needs to access the device location information when running in the background, it must be configured to be able to run in the background and be granted the **ohos.permission.LOCATION_IN_BACKGROUND** permission. In this way, the system continues to report device location information after your application moves to the background.
S
shawn_he 已提交
34 35

You can declare the required permission in your application's configuration file. For details, see [Access Control (Permission) Development](../../security/accesstoken-guidelines.md).
Z
zengyawen 已提交
36 37 38 39


## Modules to Import

S
shawn_he 已提交
40
```ts
Z
zengyawen 已提交
41 42 43
import geolocation from '@ohos.geolocation';
```

S
shawn_he 已提交
44
## geolocation.on('locationChange')<sup>(deprecated)</sup>
Z
zengyawen 已提交
45

L
liu-binjun 已提交
46
on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Location&gt;): void
Z
zengyawen 已提交
47

S
shawn_he 已提交
48
Registers a listener for location changes with a location request initiated.
S
shawn_he 已提交
49

S
shawn_he 已提交
50
> **NOTE**<br>
S
shawn_he 已提交
51
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('locationChange')](js-apis-geoLocationManager.md#geolocationmanageronlocationchange).
Z
zengyawen 已提交
52

S
shawn_he 已提交
53
**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
54 55 56

**System capability**: SystemCapability.Location.Location.Core

L
liu-binjun 已提交
57 58
**Parameters**

59
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
60
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
61
  | type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
S
shawn_he 已提交
62
  | request |  [LocationRequest](#locationrequestdeprecated) | Yes| Location request.|
S
shawn_he 已提交
63
  | callback | Callback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to receive the location change event.|
S
shawn_he 已提交
64

S
shawn_he 已提交
65

Z
zengyawen 已提交
66

L
liu-binjun 已提交
67
**Example**
S
shawn_he 已提交
68 69

  ```ts
L
liu-binjun 已提交
70
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
71 72
  let requestInfo:geolocation.LocationRequest = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
  let locationChange = (location:geolocation.Location):void => {
Z
zengyawen 已提交
73 74 75 76 77 78
      console.log('locationChanger: data: ' + JSON.stringify(location));
  };
  geolocation.on('locationChange', requestInfo, locationChange);
  ```


S
shawn_he 已提交
79
## geolocation.off('locationChange')<sup>(deprecated)</sup>
Z
zengyawen 已提交
80

L
liu-binjun 已提交
81
off(type: 'locationChange', callback?: Callback&lt;Location&gt;): void
Z
zengyawen 已提交
82 83 84

Unregisters the listener for location changes with the corresponding location request deleted.

S
shawn_he 已提交
85
> **NOTE**<br>
S
shawn_he 已提交
86 87 88
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('locationChange')](js-apis-geoLocationManager.md#geolocationmanagerofflocationchange).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
89 90 91

**System capability**: SystemCapability.Location.Location.Core

L
liu-binjun 已提交
92 93
**Parameters**

94
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
95
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
96
  | type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
S
shawn_he 已提交
97
  | callback | Callback&lt;[Location](#locationdeprecated)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
98

Z
zengyawen 已提交
99

L
liu-binjun 已提交
100
**Example**
S
shawn_he 已提交
101 102

  ```ts
L
liu-binjun 已提交
103
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
104 105
  let requestInfo:geolocation.LocationRequest = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
  let locationChange = (location:geolocation.Location):void => {
Z
zengyawen 已提交
106 107 108 109 110 111 112
      console.log('locationChanger: data: ' + JSON.stringify(location));
  };
  geolocation.on('locationChange', requestInfo, locationChange);
  geolocation.off('locationChange', locationChange);
  ```


S
shawn_he 已提交
113
## geolocation.on('locationServiceState')<sup>(deprecated)</sup>
Z
zengyawen 已提交
114

L
liu-binjun 已提交
115
on(type: 'locationServiceState', callback: Callback&lt;boolean&gt;): void
Z
zengyawen 已提交
116 117 118

Registers a listener for location service status change events.

S
shawn_he 已提交
119
> **NOTE**<br>
S
shawn_he 已提交
120 121 122
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('locationEnabledChange')](js-apis-geoLocationManager.md#geolocationmanageronlocationenabledchange).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
123 124 125

**System capability**: SystemCapability.Location.Location.Core

L
liu-binjun 已提交
126 127
**Parameters**

128
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
129
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
130
  | type | string | Yes| Event type. The value **locationServiceState** indicates a location service status change event.|
S
shawn_he 已提交
131
  | callback | Callback&lt;boolean&gt; | Yes| Callback used to receive the location service status change event.|
S
shawn_he 已提交
132

Z
zengyawen 已提交
133

L
liu-binjun 已提交
134
**Example**
S
shawn_he 已提交
135 136

  ```ts
L
liu-binjun 已提交
137
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
138
  let locationServiceState = (state:boolean):void => {
L
liu-binjun 已提交
139
      console.log('locationServiceState: ' + JSON.stringify(state));
Z
zengyawen 已提交
140 141 142 143 144
  }
  geolocation.on('locationServiceState', locationServiceState);
  ```


S
shawn_he 已提交
145
## geolocation.off('locationServiceState')<sup>(deprecated)</sup>
Z
zengyawen 已提交
146

L
liu-binjun 已提交
147
off(type: 'locationServiceState', callback?: Callback&lt;boolean&gt;): void;
Z
zengyawen 已提交
148 149 150

Unregisters the listener for location service status change events.

S
shawn_he 已提交
151
> **NOTE**<br>
S
shawn_he 已提交
152 153 154
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('locationEnabledChange')](js-apis-geoLocationManager.md#geolocationmanagerofflocationenabledchange).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
155 156 157

**System capability**: SystemCapability.Location.Location.Core

L
liu-binjun 已提交
158 159
**Parameters**

160
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
161
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
162
  | type | string | Yes| Event type. The value **locationServiceState** indicates a location service status change event.|
S
shawn_he 已提交
163
  | callback | Callback&lt;boolean&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
164

Z
zengyawen 已提交
165

L
liu-binjun 已提交
166
**Example**
S
shawn_he 已提交
167 168

  ```ts
L
liu-binjun 已提交
169
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
170
  let locationServiceState = (state:boolean):void => {
L
liu-binjun 已提交
171
      console.log('locationServiceState: state: ' + JSON.stringify(state));
Z
zengyawen 已提交
172 173 174 175 176 177
  }
  geolocation.on('locationServiceState', locationServiceState);
  geolocation.off('locationServiceState', locationServiceState);
  ```


S
shawn_he 已提交
178
## geolocation.on('cachedGnssLocationsReporting')<sup>(deprecated)</sup>
Z
zengyawen 已提交
179

L
liu-binjun 已提交
180
on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, callback: Callback&lt;Array&lt;Location&gt;&gt;): void;
Z
zengyawen 已提交
181 182 183

Registers a listener for cached GNSS location reports.

S
shawn_he 已提交
184
> **NOTE**<br>
S
shawn_he 已提交
185 186 187 188
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('cachedGnssLocationsChange')](js-apis-geoLocationManager.md#geolocationmanageroncachedgnsslocationschange).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
189 190 191

**System capability**: SystemCapability.Location.Location.Gnss

L
liu-binjun 已提交
192 193
**Parameters**

194
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
195
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
196
  | type | string | Yes| Event type. The value **cachedGnssLocationsReporting** indicates reporting of cached GNSS locations.|
S
shawn_he 已提交
197
  | request |  [CachedGnssLocationsRequest](#cachedgnsslocationsrequestdeprecated) | Yes| Request for reporting cached GNSS location.|
S
shawn_he 已提交
198
  | callback | Callback&lt;Array&lt;[Location](#locationdeprecated)&gt;&gt; | Yes| Callback used to receive the cached GNSS locations.|
S
shawn_he 已提交
199

Z
zengyawen 已提交
200

L
liu-binjun 已提交
201
**Example**
S
shawn_he 已提交
202 203

  ```ts
L
liu-binjun 已提交
204
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
205
  let cachedLocationsCb = (locations:Array<geolocation.Location>):void => {
L
liu-binjun 已提交
206
      console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
Z
zengyawen 已提交
207
  }
S
shawn_he 已提交
208
  let requestInfo:geolocation.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
Z
zengyawen 已提交
209 210 211 212
  geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
  ```


S
shawn_he 已提交
213
## geolocation.off('cachedGnssLocationsReporting')<sup>(deprecated)</sup>
Z
zengyawen 已提交
214

L
liu-binjun 已提交
215
off(type: 'cachedGnssLocationsReporting', callback?: Callback&lt;Array&lt;Location&gt;&gt;): void;
Z
zengyawen 已提交
216 217 218

Unregisters the listener for cached GNSS location reports.

S
shawn_he 已提交
219
> **NOTE**<br>
S
shawn_he 已提交
220 221 222 223
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('cachedGnssLocationsChange')](js-apis-geoLocationManager.md#geolocationmanageroffcachedgnsslocationschange).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
224 225 226

**System capability**: SystemCapability.Location.Location.Gnss

L
liu-binjun 已提交
227 228
**Parameters**

229
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
230
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
231
  | type | string | Yes| Event type. The value **cachedGnssLocationsReporting** indicates reporting of cached GNSS locations.|
S
shawn_he 已提交
232
  | callback | Callback&lt;Array&lt;[Location](#locationdeprecated)&gt;&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
233

Z
zengyawen 已提交
234

L
liu-binjun 已提交
235
**Example**
S
shawn_he 已提交
236 237

  ```ts
L
liu-binjun 已提交
238
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
239
  let cachedLocationsCb = (locations:Array<geolocation.Location>):void => {
L
liu-binjun 已提交
240
      console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
Z
zengyawen 已提交
241
  }
S
shawn_he 已提交
242
  let requestInfo:geolocation.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
Z
zengyawen 已提交
243 244 245 246 247
  geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
  geolocation.off('cachedGnssLocationsReporting');
  ```


S
shawn_he 已提交
248
## geolocation.on('gnssStatusChange')<sup>(deprecated)</sup>
Z
zengyawen 已提交
249

L
liu-binjun 已提交
250
on(type: 'gnssStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;): void;
Z
zengyawen 已提交
251 252 253

Registers a listener for GNSS satellite status change events.

S
shawn_he 已提交
254
> **NOTE**<br>
S
shawn_he 已提交
255 256 257 258
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('satelliteStatusChange')](js-apis-geoLocationManager.md#geolocationmanageronsatellitestatuschange).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
259 260 261

**System capability**: SystemCapability.Location.Location.Gnss

L
liu-binjun 已提交
262 263
**Parameters**

264
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
265
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
266
  | type | string | Yes| Event type. The value **gnssStatusChange** indicates a GNSS satellite status change.|
S
shawn_he 已提交
267
  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfodeprecated)&gt; | Yes| Callback used to receive GNSS satellite status changes.|
S
shawn_he 已提交
268

Z
zengyawen 已提交
269

L
liu-binjun 已提交
270
**Example**
S
shawn_he 已提交
271 272

  ```ts
L
liu-binjun 已提交
273
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
274
  let gnssStatusCb = (satelliteStatusInfo:geolocation.SatelliteStatusInfo):void => {
L
liu-binjun 已提交
275
      console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
Z
zengyawen 已提交
276 277 278 279 280
  }
  geolocation.on('gnssStatusChange', gnssStatusCb);
  ```


S
shawn_he 已提交
281
## geolocation.off('gnssStatusChange')<sup>(deprecated)</sup>
Z
zengyawen 已提交
282

L
liu-binjun 已提交
283
off(type: 'gnssStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;): void;
Z
zengyawen 已提交
284 285 286

Unregisters the listener for GNSS satellite status change events.

S
shawn_he 已提交
287
> **NOTE**<br>
S
shawn_he 已提交
288 289 290 291
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('satelliteStatusChange')](js-apis-geoLocationManager.md#geolocationmanageroffsatellitestatuschange).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
292 293 294

**System capability**: SystemCapability.Location.Location.Gnss

L
liu-binjun 已提交
295 296
**Parameters**

297
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
298
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
299
  | type | string | Yes| Event type. The value **gnssStatusChange** indicates a GNSS satellite status change.|
S
shawn_he 已提交
300
  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfodeprecated)&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
Z
zengyawen 已提交
301

L
liu-binjun 已提交
302
**Example**
S
shawn_he 已提交
303 304

  ```ts
L
liu-binjun 已提交
305
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
306
  let gnssStatusCb = (satelliteStatusInfo:geolocation.SatelliteStatusInfo) => {
L
liu-binjun 已提交
307
      console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
Z
zengyawen 已提交
308 309 310 311 312 313
  }
  geolocation.on('gnssStatusChange', gnssStatusCb);
  geolocation.off('gnssStatusChange', gnssStatusCb);
  ```


S
shawn_he 已提交
314
## geolocation.on('nmeaMessageChange')<sup>(deprecated)</sup>
Z
zengyawen 已提交
315

L
liu-binjun 已提交
316
on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;): void;
Z
zengyawen 已提交
317 318 319

Registers a listener for GNSS NMEA message change events.

S
shawn_he 已提交
320
> **NOTE**<br>
S
shawn_he 已提交
321 322 323 324
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('nmeaMessage')](js-apis-geoLocationManager.md#geolocationmanageronnmeamessage).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
325 326 327

**System capability**: SystemCapability.Location.Location.Gnss

L
liu-binjun 已提交
328 329
**Parameters**

330
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
331
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
332
  | type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.|
S
shawn_he 已提交
333
  | callback | Callback&lt;string&gt; | Yes| Callback used to receive GNSS NMEA message changes.|
S
shawn_he 已提交
334

Z
zengyawen 已提交
335

L
liu-binjun 已提交
336
**Example**
S
shawn_he 已提交
337 338

  ```ts
L
liu-binjun 已提交
339
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
340
  let nmeaCb = (str:string):void => {
L
liu-binjun 已提交
341
      console.log('nmeaMessageChange: ' + JSON.stringify(str));
Z
zengyawen 已提交
342 343 344 345 346
  }
  geolocation.on('nmeaMessageChange', nmeaCb );
  ```


S
shawn_he 已提交
347
## geolocation.off('nmeaMessageChange')<sup>(deprecated)</sup>
Z
zengyawen 已提交
348

L
liu-binjun 已提交
349
off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;): void;
Z
zengyawen 已提交
350 351 352

Unregisters the listener for GNSS NMEA message change events.

S
shawn_he 已提交
353
> **NOTE**<br>
S
shawn_he 已提交
354 355 356 357
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('nmeaMessage')](js-apis-geoLocationManager.md#geolocationmanageroffnmeamessage).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
358 359 360

**System capability**: SystemCapability.Location.Location.Gnss

L
liu-binjun 已提交
361 362
**Parameters**

363
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
364
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
365
  | type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.|
S
shawn_he 已提交
366
  | callback | Callback&lt;string&gt; | No| Callback to unregister. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
S
shawn_he 已提交
367

Z
zengyawen 已提交
368

L
liu-binjun 已提交
369
**Example**
S
shawn_he 已提交
370 371

  ```ts
L
liu-binjun 已提交
372
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
373
  let nmeaCb = (str:string):void => {
L
liu-binjun 已提交
374
      console.log('nmeaMessageChange: ' + JSON.stringify(str));
Z
zengyawen 已提交
375 376 377 378 379 380
  }
  geolocation.on('nmeaMessageChange', nmeaCb);
  geolocation.off('nmeaMessageChange', nmeaCb);
  ```


S
shawn_he 已提交
381
## geolocation.on('fenceStatusChange')<sup>(deprecated)</sup>
Z
zengyawen 已提交
382

L
liu-binjun 已提交
383
on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
Z
zengyawen 已提交
384 385 386

Registers a listener for status change events of the specified geofence.

S
shawn_he 已提交
387
> **NOTE**<br>
S
shawn_he 已提交
388 389 390 391
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('gnssFenceStatusChange')](js-apis-geoLocationManager.md#geolocationmanagerongnssfencestatuschange).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
392 393 394

**System capability**: SystemCapability.Location.Location.Geofence

L
liu-binjun 已提交
395 396
**Parameters**

397
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
398
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
399
  | type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.|
S
shawn_he 已提交
400
  | request |  [GeofenceRequest](#geofencerequestdeprecated) | Yes| Geofencing request.|
S
shawn_he 已提交
401
  | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
Z
zengyawen 已提交
402

L
liu-binjun 已提交
403
**Example**
S
shawn_he 已提交
404 405

  ```ts
L
liu-binjun 已提交
406
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
407
  import wantAgent from '@ohos.app.ability.wantAgent';
L
liu-binjun 已提交
408
  
S
shawn_he 已提交
409
  let wantAgentInfo:wantAgent.WantAgentInfo = {
Z
zengyawen 已提交
410 411
      wants: [
          {
L
liu-binjun 已提交
412
              bundleName: "com.example.myapplication",
S
shawn_he 已提交
413
              abilityName: "EntryAbility",
S
shawn_he 已提交
414
              action: "action1"
Z
zengyawen 已提交
415 416
          }
      ],
L
liu-binjun 已提交
417
      operationType: wantAgent.OperationType.START_ABILITY,
Z
zengyawen 已提交
418
      requestCode: 0,
L
liu-binjun 已提交
419
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG],
L
liu-binjun 已提交
420 421 422
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
S
shawn_he 已提交
423
    let requestInfo:geolocation.GeofenceRequest = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
L
liu-binjun 已提交
424 425
    geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
  });
Z
zengyawen 已提交
426 427 428
  ```


S
shawn_he 已提交
429
## geolocation.off('fenceStatusChange')<sup>(deprecated)</sup>
Z
zengyawen 已提交
430

L
liu-binjun 已提交
431
off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
Z
zengyawen 已提交
432 433 434

Unregisters the listener for status change events of the specified geofence.

S
shawn_he 已提交
435
> **NOTE**<br>
S
shawn_he 已提交
436 437 438 439
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('gnssFenceStatusChange')](js-apis-geoLocationManager.md#geolocationmanageroffgnssfencestatuschange).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
440 441 442

**System capability**: SystemCapability.Location.Location.Geofence

L
liu-binjun 已提交
443 444
**Parameters**

445
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
446
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
447
  | type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.|
S
shawn_he 已提交
448
  | request | [GeofenceRequest](#geofencerequestdeprecated) | Yes| Geofencing request.|
S
shawn_he 已提交
449
  | want | [WantAgent](js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
Z
zengyawen 已提交
450

L
liu-binjun 已提交
451
**Example**
S
shawn_he 已提交
452 453

  ```ts
L
liu-binjun 已提交
454
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
455
  import wantAgent from '@ohos.app.ability.wantAgent';
L
liu-binjun 已提交
456
  
S
shawn_he 已提交
457
  let wantAgentInfo:wantAgent.WantAgentInfo = {
Z
zengyawen 已提交
458 459
      wants: [
          {
L
liu-binjun 已提交
460
              bundleName: "com.example.myapplication",
S
shawn_he 已提交
461
              abilityName: "EntryAbility",
Z
zengyawen 已提交
462 463 464
              action: "action1",
          }
      ],
L
liu-binjun 已提交
465
      operationType: wantAgent.OperationType.START_ABILITY,
Z
zengyawen 已提交
466
      requestCode: 0,
L
liu-binjun 已提交
467 468 469 470
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
S
shawn_he 已提交
471
    let requestInfo:geolocation.GeofenceRequest = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
L
liu-binjun 已提交
472 473 474 475 476 477
    geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
    geolocation.off('fenceStatusChange', requestInfo, wantAgentObj);
  });
  ```


S
shawn_he 已提交
478
## geolocation.getCurrentLocation<sup>(deprecated)</sup>
Z
zengyawen 已提交
479

L
liu-binjun 已提交
480
getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;Location&gt;): void
Z
zengyawen 已提交
481

S
shawn_he 已提交
482
Obtains the current location. This API uses an asynchronous callback to return the result. 
Z
zengyawen 已提交
483

S
shawn_he 已提交
484
> **NOTE**<br>
S
shawn_he 已提交
485 486 487
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCurrentLocation](js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
488 489

**System capability**: SystemCapability.Location.Location.Core
Z
zengyawen 已提交
490

L
liu-binjun 已提交
491 492
**Parameters**

493
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
494
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
495
  | request | [CurrentLocationRequest](#currentlocationrequestdeprecated) | Yes| Location request.|
S
shawn_he 已提交
496
  | callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to receive the current location.|
Z
zengyawen 已提交
497

L
liu-binjun 已提交
498
**Example**
S
shawn_he 已提交
499 500

  ```ts
L
liu-binjun 已提交
501
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
502 503 504
  import BusinessError from "@ohos.base"
  let requestInfo:geolocation.CurrentLocationRequest = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
  let locationChange = (err:BusinessError.BusinessError, location:geolocation.Location) => {
L
liu-binjun 已提交
505 506 507 508 509 510
      if (err) {
          console.log('locationChanger: err=' + JSON.stringify(err));
      }
      if (location) {
          console.log('locationChanger: location=' + JSON.stringify(location));
      }
Z
zengyawen 已提交
511 512
  };
  geolocation.getCurrentLocation(requestInfo, locationChange);
S
shawn_he 已提交
513 514 515
  ```


S
shawn_he 已提交
516
## geolocation.getCurrentLocation<sup>(deprecated)</sup>
S
shawn_he 已提交
517 518 519 520 521 522

getCurrentLocation(callback: AsyncCallback&lt;Location&gt;): void


Obtains the current location. This API uses an asynchronous callback to return the result. 

S
shawn_he 已提交
523
> **NOTE**<br>
S
shawn_he 已提交
524 525 526 527 528 529 530 531 532 533
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCurrentLocation](js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation).

**Required permissions**: ohos.permission.LOCATION

**System capability**: SystemCapability.Location.Location.Core

**Parameters**

  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
534
  | callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to receive the current location.|
S
shawn_he 已提交
535 536 537 538 539

**Example**

  ```ts
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
540 541
  import BusinessError from "@ohos.base"
  let locationChange = (err:BusinessError.BusinessError, location:geolocation.Location):void => {
S
shawn_he 已提交
542 543 544 545 546 547 548
      if (err) {
          console.log('locationChanger: err=' + JSON.stringify(err));
      }
      if (location) {
          console.log('locationChanger: location=' + JSON.stringify(location));
      }
  };
Z
zengyawen 已提交
549 550 551 552
  geolocation.getCurrentLocation(locationChange);
  ```


S
shawn_he 已提交
553
## geolocation.getCurrentLocation<sup>(deprecated)</sup>
Z
zengyawen 已提交
554

L
liu-binjun 已提交
555
getCurrentLocation(request?: CurrentLocationRequest): Promise&lt;Location&gt;
Z
zengyawen 已提交
556

S
shawn_he 已提交
557 558
Obtains the current location. This API uses a promise to return the result. 

S
shawn_he 已提交
559
> **NOTE**<br>
S
shawn_he 已提交
560 561 562
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCurrentLocation](js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation-2).

**Required permissions**: ohos.permission.LOCATION
Z
zengyawen 已提交
563

S
shawn_he 已提交
564
**System capability**: SystemCapability.Location.Location.Core
Z
zengyawen 已提交
565

L
liu-binjun 已提交
566 567
**Parameters**

568
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
569
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
570
  | request | [CurrentLocationRequest](#currentlocationrequestdeprecated) | No| Location request.|
Z
zengyawen 已提交
571

L
liu-binjun 已提交
572 573
**Return value**

S
shawn_he 已提交
574 575
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
576
  | Promise&lt;[Location](#locationdeprecated)&gt; |[Location](#locationdeprecated)|NA| Promise used to return the current location.|
S
shawn_he 已提交
577

Z
zengyawen 已提交
578

L
liu-binjun 已提交
579
**Example**
S
shawn_he 已提交
580 581

  ```ts
L
liu-binjun 已提交
582
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
583
  let requestInfo:geolocation.CurrentLocationRequest = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
L
liu-binjun 已提交
584
  geolocation.getCurrentLocation(requestInfo).then((result) => {
Z
zengyawen 已提交
585 586 587 588 589
      console.log('current location: ' + JSON.stringify(result));
  });
  ```


S
shawn_he 已提交
590
## geolocation.getLastLocation<sup>(deprecated)</sup>
Z
zengyawen 已提交
591

L
liu-binjun 已提交
592
getLastLocation(callback: AsyncCallback&lt;Location&gt;): void
Z
zengyawen 已提交
593

S
shawn_he 已提交
594 595
Obtains the previous location. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
596
> **NOTE**<br>
S
shawn_he 已提交
597 598 599
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getLastLocation](js-apis-geoLocationManager.md#geolocationmanagergetlastlocation).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
600 601

**System capability**: SystemCapability.Location.Location.Core
Z
zengyawen 已提交
602

L
liu-binjun 已提交
603 604
**Parameters**

605
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
606
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
607
  | callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to receive the previous location.|
S
shawn_he 已提交
608

Z
zengyawen 已提交
609

L
liu-binjun 已提交
610
**Example**
S
shawn_he 已提交
611 612

  ```ts
L
liu-binjun 已提交
613
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
614
  geolocation.getLastLocation((err, data) => {
L
liu-binjun 已提交
615 616 617 618 619 620
      if (err) {
          console.log('getLastLocation: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('getLastLocation: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
621 622 623 624
  });
  ```


S
shawn_he 已提交
625
## geolocation.getLastLocation<sup>(deprecated)</sup>
Z
zengyawen 已提交
626

L
liu-binjun 已提交
627
getLastLocation(): Promise&lt;Location&gt;
Z
zengyawen 已提交
628

S
shawn_he 已提交
629
Obtains the previous location. This API uses a promise to return the result. 
Z
zengyawen 已提交
630

S
shawn_he 已提交
631
> **NOTE**<br>
S
shawn_he 已提交
632 633 634
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getLastLocation](js-apis-geoLocationManager.md#geolocationmanagergetlastlocation).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
635 636 637

**System capability**: SystemCapability.Location.Location.Core

L
liu-binjun 已提交
638 639
**Return value**

S
shawn_he 已提交
640 641
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
642
  | Promise&lt;[Location](#locationdeprecated)&gt; | [Location](#locationdeprecated)|NA|Promise used to return the previous location.|
S
shawn_he 已提交
643

Z
zengyawen 已提交
644

L
liu-binjun 已提交
645
**Example**
S
shawn_he 已提交
646 647

  ```ts
L
liu-binjun 已提交
648
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
649 650 651 652 653 654
  geolocation.getLastLocation().then((result) => {
      console.log('getLastLocation: result: ' + JSON.stringify(result));
  });
  ```


S
shawn_he 已提交
655
## geolocation.isLocationEnabled<sup>(deprecated)</sup>
Z
zengyawen 已提交
656

L
liu-binjun 已提交
657
isLocationEnabled(callback: AsyncCallback&lt;boolean&gt;): void
Z
zengyawen 已提交
658

S
shawn_he 已提交
659
Checks whether the location service is enabled. This API uses an asynchronous callback to return the result.
Z
zengyawen 已提交
660

S
shawn_he 已提交
661
> **NOTE**<br>
S
shawn_he 已提交
662 663 664
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isLocationEnabled](js-apis-geoLocationManager.md#geolocationmanagerislocationenabled).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
665 666

**System capability**: SystemCapability.Location.Location.Core
Z
zengyawen 已提交
667

L
liu-binjun 已提交
668 669
**Parameters**

670
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
671
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
672
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to receive the location service status.|
S
shawn_he 已提交
673

L
liu-binjun 已提交
674
**Example**
S
shawn_he 已提交
675 676

  ```ts
L
liu-binjun 已提交
677
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
678
  geolocation.isLocationEnabled((err, data) => {
L
liu-binjun 已提交
679 680 681 682 683 684
      if (err) {
          console.log('isLocationEnabled: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('isLocationEnabled: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
685 686 687 688
  });
  ```


S
shawn_he 已提交
689
## geolocation.isLocationEnabled<sup>(deprecated)</sup>
Z
zengyawen 已提交
690

L
liu-binjun 已提交
691
isLocationEnabled(): Promise&lt;boolean&gt;
Z
zengyawen 已提交
692

S
shawn_he 已提交
693 694
Checks whether the location service is enabled. This API uses a promise to return the result.

S
shawn_he 已提交
695
> **NOTE**<br>
S
shawn_he 已提交
696 697 698
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isLocationEnabled](js-apis-geoLocationManager.md#geolocationmanagerislocationenabled).

**Required permissions**: ohos.permission.LOCATION
Z
zengyawen 已提交
699

S
shawn_he 已提交
700 701
**System capability**: SystemCapability.Location.Location.Core

L
liu-binjun 已提交
702 703
**Return value**

S
shawn_he 已提交
704 705 706
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;boolean&gt; | boolean|NA|Promise used to return the location service status.|
Z
zengyawen 已提交
707

L
liu-binjun 已提交
708
**Example**
S
shawn_he 已提交
709 710

  ```ts
L
liu-binjun 已提交
711
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
712
  geolocation.isLocationEnabled().then((result) => {
L
liu-binjun 已提交
713
      console.log('promise, isLocationEnabled: ' + JSON.stringify(result));
Z
zengyawen 已提交
714 715 716 717
  });
  ```


S
shawn_he 已提交
718
## geolocation.requestEnableLocation<sup>(deprecated)</sup>
Z
zengyawen 已提交
719

L
liu-binjun 已提交
720
requestEnableLocation(callback: AsyncCallback&lt;boolean&gt;): void
Z
zengyawen 已提交
721

S
shawn_he 已提交
722 723
Requests to enable the location service. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
724
> **NOTE**<br>
S
shawn_he 已提交
725
> This API has been discarded since API version 9. It is recommended that a dialog box be displayed in the application to request the user to go to Settings to enable the location function and specify the scenarios in which the location information will be used in the dialog box.
S
shawn_he 已提交
726 727

**Required permissions**: ohos.permission.LOCATION
Z
zengyawen 已提交
728

S
shawn_he 已提交
729
**System capability**: SystemCapability.Location.Location.Core
Z
zengyawen 已提交
730

L
liu-binjun 已提交
731 732
**Parameters**

733
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
734
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
735
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to receive the location service status.|
S
shawn_he 已提交
736

L
liu-binjun 已提交
737
**Example**
S
shawn_he 已提交
738 739

  ```ts
L
liu-binjun 已提交
740
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
741
  geolocation.requestEnableLocation((err, data) => {
L
liu-binjun 已提交
742 743 744 745 746 747
      if (err) {
          console.log('requestEnableLocation: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('requestEnableLocation: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
748 749 750 751
  });
  ```


S
shawn_he 已提交
752
## geolocation.requestEnableLocation<sup>(deprecated)</sup>
Z
zengyawen 已提交
753

L
liu-binjun 已提交
754
requestEnableLocation(): Promise&lt;boolean&gt;
Z
zengyawen 已提交
755

S
shawn_he 已提交
756
Requests to enable the location service. This API uses a promise to return the result.
Z
zengyawen 已提交
757

S
shawn_he 已提交
758
> **NOTE**<br>
S
shawn_he 已提交
759
> This API has been discarded since API version 9. It is recommended that a dialog box be displayed in the application to request the user to go to Settings to enable the location function and specify the scenarios in which the location information will be used in the dialog box.
S
shawn_he 已提交
760

S
shawn_he 已提交
761
**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
762 763 764

**System capability**: SystemCapability.Location.Location.Core

L
liu-binjun 已提交
765 766
**Return value**

767
  | Name| Type| Mandatory| Description|
S
shawn_he 已提交
768
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
769
  | Promise&lt;boolean&gt; | boolean|NA|Promise used to return the location service status.|
S
shawn_he 已提交
770

L
liu-binjun 已提交
771
**Example**
S
shawn_he 已提交
772

S
shawn_he 已提交
773
  ```ts
L
liu-binjun 已提交
774
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
775 776
  geolocation.requestEnableLocation().then((result) => {
      console.log('promise, requestEnableLocation: ' + JSON.stringify(result));
S
shawn_he 已提交
777 778 779
  });
  ```

S
shawn_he 已提交
780

S
shawn_he 已提交
781
## geolocation.isGeoServiceAvailable<sup>(deprecated)</sup>
Z
zengyawen 已提交
782

L
liu-binjun 已提交
783
isGeoServiceAvailable(callback: AsyncCallback&lt;boolean&gt;): void
Z
zengyawen 已提交
784

S
shawn_he 已提交
785 786
Checks whether the (reverse) geocoding service is available. This API uses an asynchronous callback to return the result.

S
shawn_he 已提交
787
> **NOTE**<br>
S
shawn_he 已提交
788 789 790
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isGeocoderAvailable](js-apis-geoLocationManager.md#geolocationmanagerisgeocoderavailable).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
791 792

**System capability**: SystemCapability.Location.Location.Geocoder
Z
zengyawen 已提交
793

L
liu-binjun 已提交
794 795
**Parameters**

796
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
797
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
798
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to receive the (reverse) geocoding service status.|
S
shawn_he 已提交
799

L
liu-binjun 已提交
800
**Example**
S
shawn_he 已提交
801 802

  ```ts
L
liu-binjun 已提交
803
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
804
  geolocation.isGeoServiceAvailable((err, data) => {
L
liu-binjun 已提交
805 806 807 808 809 810
      if (err) {
          console.log('isGeoServiceAvailable: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('isGeoServiceAvailable: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
811 812 813 814
  });
  ```


S
shawn_he 已提交
815
## geolocation.isGeoServiceAvailable<sup>(deprecated)</sup>
Z
zengyawen 已提交
816

L
liu-binjun 已提交
817
isGeoServiceAvailable(): Promise&lt;boolean&gt;
Z
zengyawen 已提交
818

S
shawn_he 已提交
819 820
Checks whether the (reverse) geocoding service is available. This API uses a promise to return the result.

S
shawn_he 已提交
821
> **NOTE**<br>
S
shawn_he 已提交
822 823 824
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isGeocoderAvailable](js-apis-geoLocationManager.md#geolocationmanagerisgeocoderavailable).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
825 826

**System capability**: SystemCapability.Location.Location.Geocoder
Z
zengyawen 已提交
827

L
liu-binjun 已提交
828 829
**Return value**

S
shawn_he 已提交
830 831 832
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;boolean&gt; |boolean|NA| Promise used to return the (reverse) geocoding service status.|
S
shawn_he 已提交
833

L
liu-binjun 已提交
834
**Example**
S
shawn_he 已提交
835 836

  ```ts
L
liu-binjun 已提交
837
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
838
  geolocation.isGeoServiceAvailable().then((result) => {
L
liu-binjun 已提交
839
      console.log('promise, isGeoServiceAvailable: ' + JSON.stringify(result));
Z
zengyawen 已提交
840 841 842 843
  });
  ```


S
shawn_he 已提交
844
## geolocation.getAddressesFromLocation<sup>(deprecated)</sup>
Z
zengyawen 已提交
845

L
liu-binjun 已提交
846
getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
Z
zengyawen 已提交
847

S
shawn_he 已提交
848
Converts coordinates into geographic descriptions through reverse geocoding. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
849

S
shawn_he 已提交
850
> **NOTE**<br>
S
shawn_he 已提交
851 852 853
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocation](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocation).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
854 855

**System capability**: SystemCapability.Location.Location.Geocoder
Z
zengyawen 已提交
856

L
liu-binjun 已提交
857 858
**Parameters**

859
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
860
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
861
  | request | [ReverseGeoCodeRequest](#reversegeocoderequestdeprecated) | Yes| Reverse geocoding request.|
S
shawn_he 已提交
862
  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Yes| Callback used to receive the reverse geocoding result.|
Z
zengyawen 已提交
863

L
liu-binjun 已提交
864
**Example**
S
shawn_he 已提交
865 866

  ```ts
L
liu-binjun 已提交
867
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
868
  let reverseGeocodeRequest:geolocation.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
Z
zengyawen 已提交
869
  geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
L
liu-binjun 已提交
870 871 872 873 874 875
      if (err) {
          console.log('getAddressesFromLocation: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('getAddressesFromLocation: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
876 877 878 879
  });
  ```


S
shawn_he 已提交
880
## geolocation.getAddressesFromLocation<sup>(deprecated)</sup>
Z
zengyawen 已提交
881

L
liu-binjun 已提交
882
getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;;
Z
zengyawen 已提交
883

S
shawn_he 已提交
884
Converts coordinates into geographic descriptions through reverse geocoding. This API uses a promise to return the result. 
S
shawn_he 已提交
885

S
shawn_he 已提交
886
> **NOTE**<br>
S
shawn_he 已提交
887 888 889
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocation](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocation-1).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
890 891

**System capability**: SystemCapability.Location.Location.Geocoder
Z
zengyawen 已提交
892

L
liu-binjun 已提交
893 894
**Parameters**

895
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
896
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
897
  | request | [ReverseGeoCodeRequest](#reversegeocoderequestdeprecated) | Yes| Reverse geocoding request.|
Z
zengyawen 已提交
898

L
liu-binjun 已提交
899 900
**Return value**

S
shawn_he 已提交
901 902
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
903
  | Promise&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;|NA|Promise used to return the reverse geocoding result.|
Z
zengyawen 已提交
904

L
liu-binjun 已提交
905
**Example**
S
shawn_he 已提交
906 907

  ```ts
L
liu-binjun 已提交
908
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
909
  let reverseGeocodeRequest:geolocation.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
Z
zengyawen 已提交
910 911 912 913 914 915
  geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
      console.log('getAddressesFromLocation: ' + JSON.stringify(data));
  });
  ```


S
shawn_he 已提交
916
## geolocation.getAddressesFromLocationName<sup>(deprecated)</sup>
Z
zengyawen 已提交
917

L
liu-binjun 已提交
918
getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
Z
zengyawen 已提交
919

S
shawn_he 已提交
920
Converts geographic descriptions into coordinates through geocoding. This API uses an asynchronous callback to return the result. 
S
shawn_he 已提交
921

S
shawn_he 已提交
922
> **NOTE**<br>
S
shawn_he 已提交
923 924 925
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocationName](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocationname).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
926 927

**System capability**: SystemCapability.Location.Location.Geocoder
Z
zengyawen 已提交
928

L
liu-binjun 已提交
929 930
**Parameters**

931
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
932
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
933
  | request | [GeoCodeRequest](#geocoderequestdeprecated) | Yes| Geocoding request.|
S
shawn_he 已提交
934
  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Yes| Callback used to receive the geocoding result.|
S
shawn_he 已提交
935

L
liu-binjun 已提交
936
**Example**
S
shawn_he 已提交
937 938

  ```ts
L
liu-binjun 已提交
939
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
940
  let geocodeRequest:geolocation.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
Z
zengyawen 已提交
941
  geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => {
L
liu-binjun 已提交
942 943 944 945 946 947
      if (err) {
          console.log('getAddressesFromLocationName: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('getAddressesFromLocationName: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
948 949 950 951
  });
  ```


S
shawn_he 已提交
952
## geolocation.getAddressesFromLocationName<sup>(deprecated)</sup>
Z
zengyawen 已提交
953

L
liu-binjun 已提交
954
getAddressesFromLocationName(request: GeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;
Z
zengyawen 已提交
955

S
shawn_he 已提交
956
Converts geographic descriptions into coordinates through geocoding. This API uses a promise to return the result. 
S
shawn_he 已提交
957

S
shawn_he 已提交
958
> **NOTE**<br>
S
shawn_he 已提交
959 960 961
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocationName](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocationname-1).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
962 963

**System capability**: SystemCapability.Location.Location.Geocoder
Z
zengyawen 已提交
964

L
liu-binjun 已提交
965 966
**Parameters**

967
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
968
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
969
  | request | [GeoCodeRequest](#geocoderequestdeprecated) | Yes| Geocoding request.|
Z
zengyawen 已提交
970

L
liu-binjun 已提交
971 972
**Return value**

S
shawn_he 已提交
973 974
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
975
  | Promise&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;|NA|Promise used to receive the geocoding result.|
Z
zengyawen 已提交
976

L
liu-binjun 已提交
977
**Example**
S
shawn_he 已提交
978 979

  ```ts
L
liu-binjun 已提交
980
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
981
  let geocodeRequest:geolocation.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
Z
zengyawen 已提交
982 983 984 985 986 987
  geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
      console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
  });
  ```


S
shawn_he 已提交
988
## geolocation.getCachedGnssLocationsSize<sup>(deprecated)</sup>
Z
zengyawen 已提交
989

L
liu-binjun 已提交
990
getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;): void;
Z
zengyawen 已提交
991

S
shawn_he 已提交
992 993
Obtains the number of cached GNSS locations. 

S
shawn_he 已提交
994
> **NOTE**<br>
S
shawn_he 已提交
995 996 997 998
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCachedGnssLocationsSize](js-apis-geoLocationManager.md#geolocationmanagergetcachedgnsslocationssize).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
999 1000

**System capability**: SystemCapability.Location.Location.Gnss
Z
zengyawen 已提交
1001

L
liu-binjun 已提交
1002 1003
**Parameters**

1004
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
1005
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1006
  | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to receive the number of cached GNSS locations. |
Z
zengyawen 已提交
1007

L
liu-binjun 已提交
1008
**Example**
S
shawn_he 已提交
1009 1010

  ```ts
L
liu-binjun 已提交
1011
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
1012
  geolocation.getCachedGnssLocationsSize((err, size) => {
L
liu-binjun 已提交
1013 1014 1015 1016 1017 1018
      if (err) {
          console.log('getCachedGnssLocationsSize: err=' + JSON.stringify(err));
      }
      if (size) {
          console.log('getCachedGnssLocationsSize: size=' + JSON.stringify(size));
      }
Z
zengyawen 已提交
1019 1020 1021 1022
  });
  ```


S
shawn_he 已提交
1023
## geolocation.getCachedGnssLocationsSize<sup>(deprecated)</sup>
Z
zengyawen 已提交
1024

L
liu-binjun 已提交
1025
getCachedGnssLocationsSize(): Promise&lt;number&gt;;
Z
zengyawen 已提交
1026

S
shawn_he 已提交
1027
Obtains the number of cached GNSS locations. 
Z
zengyawen 已提交
1028

S
shawn_he 已提交
1029
> **NOTE**<br>
S
shawn_he 已提交
1030 1031 1032 1033
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCachedGnssLocationsSize](js-apis-geoLocationManager.md#geolocationmanagergetcachedgnsslocationssize-1).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1034 1035 1036

**System capability**: SystemCapability.Location.Location.Gnss

L
liu-binjun 已提交
1037 1038
**Return value**

S
shawn_he 已提交
1039 1040 1041
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;number&gt; | number|NA|Promise used to return the number of cached GNSS locations.|
Z
zengyawen 已提交
1042

L
liu-binjun 已提交
1043
**Example**
S
shawn_he 已提交
1044 1045

  ```ts
L
liu-binjun 已提交
1046
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
1047
  geolocation.getCachedGnssLocationsSize().then((result) => {
L
liu-binjun 已提交
1048
      console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
Z
zengyawen 已提交
1049 1050 1051 1052
  });
  ```


S
shawn_he 已提交
1053
## geolocation.flushCachedGnssLocations<sup>(deprecated)</sup>
Z
zengyawen 已提交
1054

L
liu-binjun 已提交
1055
flushCachedGnssLocations(callback: AsyncCallback&lt;boolean&gt;): void;
Z
zengyawen 已提交
1056

S
shawn_he 已提交
1057 1058
Obtains all cached GNSS locations and clears the GNSS cache queue. 

S
shawn_he 已提交
1059
> **NOTE**<br>
S
shawn_he 已提交
1060 1061 1062 1063
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.flushCachedGnssLocations](js-apis-geoLocationManager.md#geolocationmanagerflushcachedgnsslocations).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1064 1065

**System capability**: SystemCapability.Location.Location.Gnss
Z
zengyawen 已提交
1066

L
liu-binjun 已提交
1067 1068
**Parameters**

1069
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
1070
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1071
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to receive the operation result.|
Z
zengyawen 已提交
1072

L
liu-binjun 已提交
1073
**Example**
S
shawn_he 已提交
1074 1075

  ```ts
L
liu-binjun 已提交
1076
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
1077
  geolocation.flushCachedGnssLocations((err, result) => {
L
liu-binjun 已提交
1078 1079 1080 1081 1082 1083
      if (err) {
          console.log('flushCachedGnssLocations: err=' + JSON.stringify(err));
      }
      if (result) {
          console.log('flushCachedGnssLocations: result=' + JSON.stringify(result));
      }
Z
zengyawen 已提交
1084 1085 1086 1087
  });
  ```


S
shawn_he 已提交
1088
## geolocation.flushCachedGnssLocations<sup>(deprecated)</sup>
Z
zengyawen 已提交
1089

L
liu-binjun 已提交
1090
flushCachedGnssLocations(): Promise&lt;boolean&gt;;
Z
zengyawen 已提交
1091

S
shawn_he 已提交
1092 1093
Obtains all cached GNSS locations and clears the GNSS cache queue. 

S
shawn_he 已提交
1094
> **NOTE**<br>
S
shawn_he 已提交
1095 1096 1097 1098
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.flushCachedGnssLocations](js-apis-geoLocationManager.md#geolocationmanagerflushcachedgnsslocations-1).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1099 1100

**System capability**: SystemCapability.Location.Location.Gnss
Z
zengyawen 已提交
1101

L
liu-binjun 已提交
1102 1103
**Return value**

S
shawn_he 已提交
1104 1105
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1106
  | Promise&lt;boolean&gt; |boolean|NA| Promise used to indicate whether the cached GNSS locations are cleared successfully.|
Z
zengyawen 已提交
1107

L
liu-binjun 已提交
1108
**Example**
S
shawn_he 已提交
1109 1110

  ```ts
L
liu-binjun 已提交
1111
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
1112
  geolocation.flushCachedGnssLocations().then((result) => {
L
liu-binjun 已提交
1113
      console.log('promise, flushCachedGnssLocations: ' + JSON.stringify(result));
Z
zengyawen 已提交
1114 1115 1116 1117
  });
  ```


S
shawn_he 已提交
1118
## geolocation.sendCommand<sup>(deprecated)</sup>
Z
zengyawen 已提交
1119

L
liu-binjun 已提交
1120
sendCommand(command: LocationCommand, callback: AsyncCallback&lt;boolean&gt;): void;
Z
zengyawen 已提交
1121

S
shawn_he 已提交
1122 1123
Sends an extended command to the location subsystem. 

S
shawn_he 已提交
1124
> **NOTE**<br>
S
shawn_he 已提交
1125 1126
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.sendCommand](js-apis-geoLocationManager.md#geolocationmanagersendcommand).
S
shawn_he 已提交
1127

S
shawn_he 已提交
1128
**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1129 1130

**System capability**: SystemCapability.Location.Location.Core
Z
zengyawen 已提交
1131

L
liu-binjun 已提交
1132 1133
**Parameters**

1134
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
1135
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1136
  | command |  [LocationCommand](#locationcommanddeprecated) | Yes| Extended command (string) to be sent.|
S
shawn_he 已提交
1137
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to receive the operation result.|
Z
zengyawen 已提交
1138

L
liu-binjun 已提交
1139
**Example**
S
shawn_he 已提交
1140 1141

  ```ts
L
liu-binjun 已提交
1142
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
1143
  let requestInfo:geolocation.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
Z
zengyawen 已提交
1144
  geolocation.sendCommand(requestInfo, (err, result) => {
L
liu-binjun 已提交
1145 1146 1147 1148 1149 1150
      if (err) {
          console.log('sendCommand: err=' + JSON.stringify(err));
      }
      if (result) {
          console.log('sendCommand: result=' + JSON.stringify(result));
      }
Z
zengyawen 已提交
1151 1152 1153 1154
  });
  ```


S
shawn_he 已提交
1155
## geolocation.sendCommand<sup>(deprecated)</sup>
Z
zengyawen 已提交
1156

L
liu-binjun 已提交
1157
sendCommand(command: LocationCommand): Promise&lt;boolean&gt;;
Z
zengyawen 已提交
1158

S
shawn_he 已提交
1159 1160
Sends an extended command to the location subsystem. 

S
shawn_he 已提交
1161
> **NOTE**<br>
S
shawn_he 已提交
1162 1163
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.sendCommand](js-apis-geoLocationManager.md#geolocationmanagersendcommand).
S
shawn_he 已提交
1164

S
shawn_he 已提交
1165
**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1166 1167

**System capability**: SystemCapability.Location.Location.Core
Z
zengyawen 已提交
1168

L
liu-binjun 已提交
1169 1170
**Parameters**

1171
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
1172
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1173
  | command | [LocationCommand](#locationcommanddeprecated) | Yes| Extended command (string) to be sent.|
Z
zengyawen 已提交
1174

L
liu-binjun 已提交
1175 1176
**Return value**

S
shawn_he 已提交
1177 1178 1179
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;boolean&gt; |boolean|NA| Callback used to return the operation result.|
Z
zengyawen 已提交
1180

L
liu-binjun 已提交
1181
**Example**
S
shawn_he 已提交
1182 1183

  ```ts
L
liu-binjun 已提交
1184
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
1185
  let requestInfo:geolocation.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
Z
zengyawen 已提交
1186
  geolocation.sendCommand(requestInfo).then((result) => {
L
liu-binjun 已提交
1187
      console.log('promise, sendCommand: ' + JSON.stringify(result));
Z
zengyawen 已提交
1188 1189 1190 1191
  });
  ```


S
shawn_he 已提交
1192
## ReverseGeoCodeRequest<sup>(deprecated)</sup>
L
liu-binjun 已提交
1193

L
liu-binjun 已提交
1194
Defines a reverse geocoding request.
Z
zengyawen 已提交
1195

S
shawn_he 已提交
1196
> **NOTE**<br>
S
shawn_he 已提交
1197 1198 1199
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.ReverseGeoCodeRequest](js-apis-geoLocationManager.md#reversegeocoderequest).

**Required permissions**: ohos.permission.LOCATION
Z
zengyawen 已提交
1200

L
liu-binjun 已提交
1201
**System capability**: SystemCapability.Location.Location.Geocoder
Z
zengyawen 已提交
1202

S
shawn_he 已提交
1203 1204 1205
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
S
shawn_he 已提交
1206 1207 1208
| latitude | number | Yes| Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.|
| longitude | number | Yes| Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.|
| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
Z
zengyawen 已提交
1209 1210


S
shawn_he 已提交
1211
## GeoCodeRequest<sup>(deprecated)</sup>
S
shawn_he 已提交
1212

L
liu-binjun 已提交
1213
Defines a geocoding request.
S
shawn_he 已提交
1214

S
shawn_he 已提交
1215
> **NOTE**<br>
S
shawn_he 已提交
1216 1217 1218
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.GeoCodeRequest](js-apis-geoLocationManager.md#geocoderequest).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1219

L
liu-binjun 已提交
1220
**System capability**: SystemCapability.Location.Location.Geocoder
Z
zengyawen 已提交
1221

S
shawn_he 已提交
1222 1223 1224 1225
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| description | string | Yes| Yes| Location description, for example, **No. xx, xx Road, Pudong New District, Shanghai**.|
S
shawn_he 已提交
1226 1227 1228 1229 1230
| maxItems | number | Yes| Yes| Maximum number of location records to be returned. The value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
| minLatitude | number | Yes| Yes| Minimum latitude. This parameter is used with **minLongitude**, **maxLatitude**, and **maxLongitude** to specify the latitude and longitude ranges. The value ranges from **-90** to **90**.|
| minLongitude | number | Yes| Yes| Minimum longitude. The value ranges from **-180** to **180**.|
| maxLatitude | number | Yes| Yes| Maximum latitude. The value ranges from **-90** to **90**.|
| maxLongitude | number | Yes| Yes| Maximum longitude. The value ranges from **-180** to **180**.|
L
liu-binjun 已提交
1231

Z
zengyawen 已提交
1232

S
shawn_he 已提交
1233
## GeoAddress<sup>(deprecated)</sup>
L
liu-binjun 已提交
1234 1235 1236

Defines a geographic location.

S
shawn_he 已提交
1237
> **NOTE**<br>
S
shawn_he 已提交
1238 1239 1240
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.GeoAddress](js-apis-geoLocationManager.md#geoaddress).

**Required permissions**: ohos.permission.LOCATION
Z
zengyawen 已提交
1241

L
liu-binjun 已提交
1242
**System capability**: SystemCapability.Location.Location.Geocoder
Z
zengyawen 已提交
1243

S
shawn_he 已提交
1244 1245
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1246 1247
| latitude<sup>7+</sup> | number | Yes| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.|
| longitude<sup>7+</sup> | number | Yes| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.|
S
shawn_he 已提交
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262
| locale<sup>7+</sup> | string | Yes| No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| placeName<sup>7+</sup> | string | Yes| No| Landmark of the location.|
| countryCode<sup>7+</sup> | string | Yes| No| Country code.|
| countryName<sup>7+</sup> | string | Yes| No| Country name.|
| administrativeArea<sup>7+</sup> | string | Yes| No| Administrative region name.|
| subAdministrativeArea<sup>7+</sup> | string | Yes| No| Sub-administrative region name.|
| locality<sup>7+</sup> | string | Yes| No| Locality information.|
| subLocality<sup>7+</sup> | string | Yes| No| Sub-locality information.|
| roadName<sup>7+</sup> | string | Yes| No| Road name.|
| subRoadName<sup>7+</sup> | string | Yes| No| Auxiliary road information.|
| premises<sup>7+</sup> | string | Yes| No| House information.|
| postalCode<sup>7+</sup> | string | Yes| No| Postal code.|
| phoneNumber<sup>7+</sup> | string | Yes| No| Phone number.|
| addressUrl<sup>7+</sup> | string | Yes| No| Website URL.|
| descriptions<sup>7+</sup> | Array&lt;string&gt; | Yes| No| Additional descriptions.|
S
shawn_he 已提交
1263
| descriptionsSize<sup>7+</sup> | number | Yes| No| Total number of additional descriptions. The value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
S
shawn_he 已提交
1264 1265


S
shawn_he 已提交
1266
## LocationRequest<sup>(deprecated)</sup>
S
shawn_he 已提交
1267

L
liu-binjun 已提交
1268
Defines a location request.
S
shawn_he 已提交
1269

S
shawn_he 已提交
1270
> **NOTE**<br>
S
shawn_he 已提交
1271 1272 1273
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationRequest](js-apis-geoLocationManager.md#locationrequest).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1274 1275

**System capability**: SystemCapability.Location.Location.Core
Z
zengyawen 已提交
1276

S
shawn_he 已提交
1277 1278
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1279 1280 1281 1282 1283
| priority | [LocationRequestPriority](#locationrequestprioritydeprecated) | Yes| Yes| Priority of the location request. For details about the value range, see [LocationRequestPriority](#locationrequestprioritydeprecated).|
| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated) | Yes| Yes| Scenario of the location request. For details about the value range, see [LocationRequestScenario](#locationrequestscenariodeprecated).|
| timeInterval | number | Yes| Yes| Time interval at which location information is reported, in seconds. The value must be greater than **0**.|
| distanceInterval | number | Yes| Yes| Distance interval at which location information is reported. The value must be greater than **0**, in meters.|
| maxAccuracy | number | Yes| Yes| Location accuracy. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled. The value must be greater than **0**.|
L
liu-binjun 已提交
1284

Z
zengyawen 已提交
1285

S
shawn_he 已提交
1286
## CurrentLocationRequest<sup>(deprecated)</sup>
L
liu-binjun 已提交
1287

L
liu-binjun 已提交
1288
Defines the current location request.
Z
zengyawen 已提交
1289

S
shawn_he 已提交
1290
> **NOTE**<br>
S
shawn_he 已提交
1291 1292 1293
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.CurrentLocationRequest](js-apis-geoLocationManager.md#currentlocationrequest).

**Required permissions**: ohos.permission.LOCATION
L
liu-binjun 已提交
1294

L
liu-binjun 已提交
1295
**System capability**: SystemCapability.Location.Location.Core
L
liu-binjun 已提交
1296

S
shawn_he 已提交
1297 1298
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1299 1300 1301 1302
| priority | [LocationRequestPriority](#locationrequestprioritydeprecated) | Yes| Yes| Priority of the location request. For details about the value range, see [LocationRequestPriority](#locationrequestprioritydeprecated).|
| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated) | Yes| Yes| Scenario of the location request. For details about the value range, see [LocationRequestScenario](#locationrequestscenariodeprecated).|
| maxAccuracy | number | Yes| Yes| Location accuracy, in meters. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled. The value must be greater than **0**.|
| timeoutMs | number | Yes| Yes| Timeout duration, in milliseconds. The minimum value is **1000**. The value must be greater than or equal to **1000**.|
L
liu-binjun 已提交
1303 1304


S
shawn_he 已提交
1305
## SatelliteStatusInfo<sup>(deprecated)</sup>
L
liu-binjun 已提交
1306

L
liu-binjun 已提交
1307
Defines the satellite status information.
L
liu-binjun 已提交
1308

S
shawn_he 已提交
1309
> **NOTE**<br>
S
shawn_he 已提交
1310 1311 1312 1313
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.SatelliteStatusInfo](js-apis-geoLocationManager.md#satellitestatusinfo).

**Required permissions**: ohos.permission.LOCATION
L
liu-binjun 已提交
1314

L
liu-binjun 已提交
1315
**System capability**: SystemCapability.Location.Location.Gnss
L
liu-binjun 已提交
1316

S
shawn_he 已提交
1317 1318
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1319 1320 1321 1322 1323 1324
| satellitesNumber | number | Yes| No| Number of satellites. The value must be greater than or equal to **0**.|
| satelliteIds | Array&lt;number&gt; | Yes| No| Array of satellite IDs. The value must be greater than or equal to **0**.|
| carrierToNoiseDensitys | Array&lt;number&gt; | Yes| No| Carrier-to-noise density ratio, that is, **cn0**. The value must be greater than **0**.|
| altitudes | Array&lt;number&gt; | Yes| No| Satellite altitude angle information. The value ranges from **-90** to **90**, in degrees.|
| azimuths | Array&lt;number&gt; | Yes| No| Azimuth information. The value ranges from **0** to **360**, in degrees.|
| carrierFrequencies | Array&lt;number&gt; | Yes| No| Carrier frequency. The value must be greater than or equal to **0**, in Hz.|
L
liu-binjun 已提交
1325 1326


S
shawn_he 已提交
1327
## CachedGnssLocationsRequest<sup>(deprecated)</sup>
L
liu-binjun 已提交
1328

L
liu-binjun 已提交
1329
Represents a request for reporting cached GNSS locations.
L
liu-binjun 已提交
1330

S
shawn_he 已提交
1331
> **NOTE**<br>
S
shawn_he 已提交
1332 1333 1334 1335
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.CachedGnssLocationsRequest](js-apis-geoLocationManager.md#cachedgnsslocationsrequest).

**Required permissions**: ohos.permission.LOCATION
L
liu-binjun 已提交
1336

L
liu-binjun 已提交
1337
**System capability**: SystemCapability.Location.Location.Gnss
S
shawn_he 已提交
1338

S
shawn_he 已提交
1339 1340
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1341
| reportingPeriodSec | number | Yes| Yes| Interval for reporting the cached GNSS locations, in milliseconds. The value must be greater than **0**.|
S
shawn_he 已提交
1342
| wakeUpCacheQueueFull | boolean | Yes| Yes | **true**: reports the cached GNSS locations to the application when the cache queue is full.<br>**false**: discards the cached GNSS locations when the cache queue is full.|
Z
zengyawen 已提交
1343 1344


S
shawn_he 已提交
1345
## Geofence<sup>(deprecated)</sup>
Z
zengyawen 已提交
1346 1347 1348

Defines a GNSS geofence. Currently, only circular geofences are supported.

S
shawn_he 已提交
1349
> **NOTE**<br>
S
shawn_he 已提交
1350 1351 1352 1353
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.Geofence](js-apis-geoLocationManager.md#geofence).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1354 1355 1356

**System capability**: SystemCapability.Location.Location.Geofence

S
shawn_he 已提交
1357 1358
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1359 1360 1361 1362
| latitude | number | Yes| Yes|Latitude information. The value ranges from **-90** to **90**.|
| longitude | number | Yes|Yes| Longitude information. The value ranges from **-180** to **180**.|
| radius | number | Yes|Yes| Radius of a circular geofence. The value must be greater than **0**, in meters.|
| expiration | number | Yes|Yes| Expiration period of a geofence, in milliseconds. The value must be greater than **0**.|
Z
zengyawen 已提交
1363 1364


S
shawn_he 已提交
1365
## GeofenceRequest<sup>(deprecated)</sup>
Z
zengyawen 已提交
1366 1367 1368

Represents a GNSS geofencing request.

S
shawn_he 已提交
1369
> **NOTE**<br>
S
shawn_he 已提交
1370 1371 1372 1373
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.GeofenceRequest](js-apis-geoLocationManager.md#geofencerequest).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1374 1375 1376

**System capability**: SystemCapability.Location.Location.Geofence

S
shawn_he 已提交
1377 1378
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1379 1380 1381
| priority | [LocationRequestPriority](#locationrequestprioritydeprecated) | Yes| Yes | Priority of the location information.|
| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated) | Yes| Yes | Location scenario.|
| geofence | [Geofence](#geofencedeprecated)| Yes| Yes | Geofence information.|
S
shawn_he 已提交
1382

Z
zengyawen 已提交
1383

S
shawn_he 已提交
1384
## LocationCommand<sup>(deprecated)</sup>
Z
zengyawen 已提交
1385 1386 1387

Defines an extended command.

S
shawn_he 已提交
1388
> **NOTE**<br>
S
shawn_he 已提交
1389 1390 1391 1392
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationCommand](js-apis-geoLocationManager.md#locationcommand).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1393 1394 1395

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
1396 1397
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1398
| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated)  | Yes| Yes | Location scenario.|
S
shawn_he 已提交
1399
| command | string | Yes| Yes | Extended command, in the string format.|
Z
zengyawen 已提交
1400 1401


S
shawn_he 已提交
1402
## Location<sup>(deprecated)</sup>
Z
zengyawen 已提交
1403 1404 1405

Defines a location.

S
shawn_he 已提交
1406
> **NOTE**<br>
S
shawn_he 已提交
1407 1408 1409
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.Location](js-apis-geoLocationManager.md#location).

**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1410 1411 1412

**System capability**: SystemCapability.Location.Location.Core

S
shawn_he 已提交
1413 1414
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1415 1416
| latitude<sup>7+</sup> | number | Yes| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.|
| longitude<sup>7+</sup> | number | Yes| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.|
S
shawn_he 已提交
1417 1418 1419 1420
| altitude<sup>7+</sup> | number | Yes| No| Location altitude, in meters.|
| accuracy<sup>7+</sup> | number | Yes| No| Location accuracy, in meters.|
| speed<sup>7+</sup> | number | Yes| No| Speed, in m/s.|
| timeStamp<sup>7+</sup> | number | Yes| No| Location timestamp in the UTC format.|
S
shawn_he 已提交
1421
| direction<sup>7+</sup> | number | Yes| No| Direction information. The value ranges from **0** to **360**, in degrees.|
S
shawn_he 已提交
1422 1423
| timeSinceBoot<sup>7+</sup> | number | Yes| No| Location timestamp since boot.|
| additions<sup>7+</sup> | Array&lt;string&gt; | Yes| No| Additional description.|
S
shawn_he 已提交
1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
| additionSize<sup>7+</sup> | number | Yes| No| Number of additional descriptions. The value must be greater than or equal to **0**.|


## LocationPrivacyType<sup>(deprecated)</sup>

Defines the privacy statement type.

> **NOTE**<br>
> This API is supported since API version 8.
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationPrivacyType](js-apis-geoLocationManager.md#locationprivacytype).

**Required permissions**: ohos.permission.LOCATION

**System capability**: SystemCapability.Location.Location.Core

| Name| Value| Description|
| -------- | -------- | -------- |
| OTHERS | 0 | Other scenarios. Reserved field.|
| STARTUP | 1 | Privacy statement displayed in the startup wizard.  |
| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.|


## LocationRequestPriority<sup>(deprecated)</sup>

Sets the priority of the location request.

> **NOTE**<br>
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationRequestPriority](js-apis-geoLocationManager.md#locationrequestpriority).

**Required permissions**: ohos.permission.LOCATION

**System capability**: SystemCapability.Location.Location.Core

| Name| Value| Description|
| -------- | -------- | -------- |
| UNSET | 0x200 | Priority unspecified.<br>If this option is used, [LocationRequestPriority](#locationrequestprioritydeprecated) is invalid.|
| ACCURACY | 0x201 | Location accuracy preferred.<br>This policy mainly uses the GNSS positioning technology. In an open area, the technology can achieve the meter-level location accuracy, depending on the hardware performance of the device. However, in a shielded environment, the location accuracy may significantly decrease.|
| LOW_POWER | 0x202 | Power efficiency preferred.<br>This policy mainly uses the base station positioning, WLAN positioning, and Bluetooth positioning technologies to obtain device location in both indoor and outdoor scenarios. The location accuracy depends on the distribution of surrounding base stations, visible WLANs, and Bluetooth devices and therefore may fluctuate greatly. This policy is recommended and can reduce power consumption when your application does not require high location accuracy or when base stations, visible WLANs, and Bluetooth devices are densely distributed.|
| FIRST_FIX | 0x203 | Fast location preferred. Use this option if you want to obtain a location as fast as possible.<br>This policy uses the GNSS positioning, base station positioning, WLAN positioning, and Bluetooth positioning technologies simultaneously to obtain the device location in both the indoor and outdoor scenarios. When all positioning technologies provide a location result, the system provides the most accurate location result for your application. It can lead to significant hardware resource consumption and power consumption.|


## LocationRequestScenario<sup>(deprecated)</sup>

  Sets the scenario of the location request.

> **NOTE**<br>
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationRequestScenario](js-apis-geoLocationManager.md#locationrequestscenario).

**Required permissions**: ohos.permission.LOCATION

**System capability**: SystemCapability.Location.Location.Core

| Name| Value| Description|
| -------- | -------- | -------- |
| UNSET | 0x300 | Scenario unspecified.<br>If this option is used, [LocationRequestScenario](#locationrequestscenariodeprecated) is invalid.|
| NAVIGATION | 0x301 | Navigation scenario.<br>This option is applicable when your application needs to obtain the real-time location of a mobile device outdoors, such as navigation for driving or walking.<br>In this scenario, GNSS positioning is used to provide location services to ensure the optimal location accuracy of the system.<br>The location result is reported at a minimum interval of 1 second by default.|
| TRAJECTORY_TRACKING | 0x302 | Trajectory tracking scenario.<br>This option is applicable when your application needs to record user trajectories, for example, the track recording function of sports applications. In this scenario, the GNSS positioning technology is mainly used to ensure the location accuracy.<br>The location result is reported at a minimum interval of 1 second by default.|
| CAR_HAILING | 0x303 | Ride hailing scenario.<br>This option is applicable when your application needs to obtain the current location of a user who is hailing a taxi.<br>The location result is reported at a minimum interval of 1 second by default.|
| DAILY_LIFE_SERVICE | 0x304 | Daily life service scenario.<br>This option is applicable when your application only needs the approximate user location for recommendations and push notifications in scenarios such as when the user is browsing news, shopping online, and ordering food.<br>The location result is reported at a minimum interval of 1 second by default.|
| NO_POWER | 0x305 | Power efficiency scenario.<br>This option is applicable when 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<sup>(deprecated)</sup>

Enumerates error codes of the location service.

> **NOTE**<br>
S
shawn_he 已提交
1491
> This API is deprecated since API version 9. You are advised to use [geoLocationManager](../errorcodes/errorcode-geoLocationManager.md).
S
shawn_he 已提交
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505

**Required permissions**: ohos.permission.LOCATION

**System capability**: SystemCapability.Location.Location.Core

| Name| 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.|