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

S
shawn_he 已提交
3
The **geolocation** module provides location services such as GNSS positioning, network positioning, geocoding, reverse geocoding, country code and geofencing.
Z
zengyawen 已提交
4

S
shawn_he 已提交
5
> **NOTE**
S
shawn_he 已提交
6 7 8
> 
> - 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.
> - The APIs provided by this module are no longer maintained since API version 9. You are advised to use [geoLocationManager](js-apis-geoLocationManager.md) instead.
S
shawn_he 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22

## 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 已提交
23
- API versions earlier than 9: Apply for **ohos.permission.LOCATION**.
S
shawn_he 已提交
24

S
shawn_he 已提交
25
- 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 已提交
26 27 28 29 30 31 32 33

| API Version| Location Permission| Permission Application Result| Location Accuracy|
| -------- | -------- | -------- | -------- |
| Earlier than 9| ohos.permission.LOCATION | Success| Location accurate to meters|
| 9 and later| ohos.permission.LOCATION | Failure| No location obtained|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers|
| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters|

S
shawn_he 已提交
34
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 已提交
35 36

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 已提交
37 38 39 40


## Modules to Import

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

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

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

S
shawn_he 已提交
49 50
Registers a listener for location changes with a location request initiated. The location result is reported through [LocationRequest](#locationrequest).

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

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

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

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

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

Z
zengyawen 已提交
66

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

  ```ts
L
liu-binjun 已提交
70
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
71 72 73 74 75 76 77 78
  var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
  var locationChange = (location) => {
      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](#location)&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';
Z
zengyawen 已提交
104 105 106 107 108 109 110 111 112
  var requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
  var locationChange = (location) => {
      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 131 132
  | type | string | Yes| Event type. The value **locationServiceState** indicates a location service status change event.|
  | callback | Callback&lt;boolean&gt; | Yes| Callback used to return the location service status change event.|

Z
zengyawen 已提交
133

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

  ```ts
L
liu-binjun 已提交
137
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
138
  var locationServiceState = (state) => {
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';
Z
zengyawen 已提交
170
  var locationServiceState = (state) => {
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**
S
shawn_he 已提交
185
> 
S
shawn_he 已提交
186 187 188 189
> 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 已提交
190 191 192

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

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

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

Z
zengyawen 已提交
201

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

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


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

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

Unregisters the listener for cached GNSS location reports.

S
shawn_he 已提交
220
> **NOTE**
S
shawn_he 已提交
221
> 
S
shawn_he 已提交
222 223 224 225
> 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 已提交
226 227 228

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

L
liu-binjun 已提交
229 230
**Parameters**

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

Z
zengyawen 已提交
236

L
liu-binjun 已提交
237
**Example**
S
shawn_he 已提交
238 239

  ```ts
L
liu-binjun 已提交
240
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
241
  var cachedLocationsCb = (locations) => {
L
liu-binjun 已提交
242
      console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
Z
zengyawen 已提交
243 244 245 246 247 248 249
  }
  var requestInfo = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
  geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
  geolocation.off('cachedGnssLocationsReporting');
  ```


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

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

Registers a listener for GNSS satellite status change events.

S
shawn_he 已提交
256
> **NOTE**
S
shawn_he 已提交
257
> 
S
shawn_he 已提交
258 259 260 261
> 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 已提交
262 263 264

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

L
liu-binjun 已提交
265 266
**Parameters**

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

Z
zengyawen 已提交
272

L
liu-binjun 已提交
273
**Example**
S
shawn_he 已提交
274 275

  ```ts
L
liu-binjun 已提交
276
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
277
  var gnssStatusCb = (satelliteStatusInfo) => {
L
liu-binjun 已提交
278
      console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
Z
zengyawen 已提交
279 280 281 282 283
  }
  geolocation.on('gnssStatusChange', gnssStatusCb);
  ```


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

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

Unregisters the listener for GNSS satellite status change events.

S
shawn_he 已提交
290
> **NOTE**
S
shawn_he 已提交
291
> 
S
shawn_he 已提交
292 293 294 295
> 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 已提交
296 297 298

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

L
liu-binjun 已提交
299 300
**Parameters**

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

L
liu-binjun 已提交
306
**Example**
S
shawn_he 已提交
307 308

  ```ts
L
liu-binjun 已提交
309
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
310
  var gnssStatusCb = (satelliteStatusInfo) => {
L
liu-binjun 已提交
311
      console.log('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
Z
zengyawen 已提交
312 313 314 315 316 317
  }
  geolocation.on('gnssStatusChange', gnssStatusCb);
  geolocation.off('gnssStatusChange', gnssStatusCb);
  ```


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

L
liu-binjun 已提交
320
on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;): void;
Z
zengyawen 已提交
321 322 323

Registers a listener for GNSS NMEA message change events.

S
shawn_he 已提交
324
> **NOTE**
S
shawn_he 已提交
325
> 
S
shawn_he 已提交
326 327 328 329
> 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 已提交
330 331 332

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

L
liu-binjun 已提交
333 334
**Parameters**

335
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
336
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
337 338 339
  | type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.|
  | callback | Callback&lt;string&gt; | Yes| Callback used to return GNSS NMEA message changes.|

Z
zengyawen 已提交
340

L
liu-binjun 已提交
341
**Example**
S
shawn_he 已提交
342 343

  ```ts
L
liu-binjun 已提交
344
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
345
  var nmeaCb = (str) => {
L
liu-binjun 已提交
346
      console.log('nmeaMessageChange: ' + JSON.stringify(str));
Z
zengyawen 已提交
347 348 349 350 351
  }
  geolocation.on('nmeaMessageChange', nmeaCb );
  ```


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

L
liu-binjun 已提交
354
off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;): void;
Z
zengyawen 已提交
355 356 357

Unregisters the listener for GNSS NMEA message change events.

S
shawn_he 已提交
358
> **NOTE**
S
shawn_he 已提交
359
> 
S
shawn_he 已提交
360 361 362 363
> 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 已提交
364 365 366

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

L
liu-binjun 已提交
367 368
**Parameters**

369
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
370
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
371
  | type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.|
S
shawn_he 已提交
372
  | 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 已提交
373

Z
zengyawen 已提交
374

L
liu-binjun 已提交
375
**Example**
S
shawn_he 已提交
376 377

  ```ts
L
liu-binjun 已提交
378
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
379
  var nmeaCb = (str) => {
L
liu-binjun 已提交
380
      console.log('nmeaMessageChange: ' + JSON.stringify(str));
Z
zengyawen 已提交
381 382 383 384 385 386
  }
  geolocation.on('nmeaMessageChange', nmeaCb);
  geolocation.off('nmeaMessageChange', nmeaCb);
  ```


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

L
liu-binjun 已提交
389
on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
Z
zengyawen 已提交
390 391 392

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

S
shawn_he 已提交
393
> **NOTE**
S
shawn_he 已提交
394
> 
S
shawn_he 已提交
395 396 397 398
> 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 已提交
399 400 401

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

L
liu-binjun 已提交
402 403
**Parameters**

404
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
405
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
406
  | type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.|
S
shawn_he 已提交
407
  | request |  [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
S
shawn_he 已提交
408 409
  | want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.|

Z
zengyawen 已提交
410

L
liu-binjun 已提交
411
**Example**
S
shawn_he 已提交
412 413

  ```ts
L
liu-binjun 已提交
414 415 416 417
  import geolocation from '@ohos.geolocation';
  import wantAgent from '@ohos.wantAgent';
  
  let wantAgentInfo = {
Z
zengyawen 已提交
418 419
      wants: [
          {
L
liu-binjun 已提交
420
              bundleName: "com.example.myapplication",
L
liu-binjun 已提交
421
              abilityName: "com.example.myapplication.MainAbility",
Z
zengyawen 已提交
422 423 424
              action: "action1",
          }
      ],
L
liu-binjun 已提交
425
      operationType: wantAgent.OperationType.START_ABILITY,
Z
zengyawen 已提交
426
      requestCode: 0,
L
liu-binjun 已提交
427
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG],
L
liu-binjun 已提交
428 429 430 431 432 433
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
    var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
    geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
  });
Z
zengyawen 已提交
434 435 436
  ```


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

L
liu-binjun 已提交
439
off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void;
Z
zengyawen 已提交
440 441 442

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

S
shawn_he 已提交
443
> **NOTE**
S
shawn_he 已提交
444
> 
S
shawn_he 已提交
445 446 447 448
> 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 已提交
449 450 451

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

L
liu-binjun 已提交
452 453
**Parameters**

454
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
455
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
456
  | type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.|
S
shawn_he 已提交
457
  | request | [GeofenceRequest](#geofencerequest) | Yes| Geofencing request.|
S
shawn_he 已提交
458
  | want | WantAgent | Yes| **WantAgent** used to return geofence (entrance or exit) events.|
Z
zengyawen 已提交
459

L
liu-binjun 已提交
460
**Example**
S
shawn_he 已提交
461 462

  ```ts
L
liu-binjun 已提交
463 464 465 466
  import geolocation from '@ohos.geolocation';
  import wantAgent from '@ohos.wantAgent';
  
  let wantAgentInfo = {
Z
zengyawen 已提交
467 468
      wants: [
          {
L
liu-binjun 已提交
469
              bundleName: "com.example.myapplication",
L
liu-binjun 已提交
470
              abilityName: "com.example.myapplication.MainAbility",
Z
zengyawen 已提交
471 472 473
              action: "action1",
          }
      ],
L
liu-binjun 已提交
474
      operationType: wantAgent.OperationType.START_ABILITY,
Z
zengyawen 已提交
475
      requestCode: 0,
L
liu-binjun 已提交
476 477 478 479 480 481 482 483 484 485 486
      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
  };
  
  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
    var requestInfo = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 121, "longitude": 26, "radius": 100, "expiration": 10000}};
    geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
    geolocation.off('fenceStatusChange', requestInfo, wantAgentObj);
  });
  ```


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

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

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

S
shawn_he 已提交
493
> **NOTE**<br>
S
shawn_he 已提交
494 495 496
> 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 已提交
497 498

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

L
liu-binjun 已提交
500 501
**Parameters**

502
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
503
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
504
  | request | [CurrentLocationRequest](#currentlocationrequest) | Yes| Location request.|
S
shawn_he 已提交
505
  | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the current location.|
Z
zengyawen 已提交
506

L
liu-binjun 已提交
507
**Example**
S
shawn_he 已提交
508 509

  ```ts
L
liu-binjun 已提交
510
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
511 512
  var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
  var locationChange = (err, location) => {
L
liu-binjun 已提交
513 514 515 516 517 518
      if (err) {
          console.log('locationChanger: err=' + JSON.stringify(err));
      }
      if (location) {
          console.log('locationChanger: location=' + JSON.stringify(location));
      }
Z
zengyawen 已提交
519 520
  };
  geolocation.getCurrentLocation(requestInfo, locationChange);
S
shawn_he 已提交
521 522 523 524 525 526 527 528 529 530
  ```


## geolocation.getCurrentLocation<sup>(deprecated) </sup>

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


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

S
shawn_he 已提交
531
> **NOTE**<br>
S
shawn_he 已提交
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
> 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|
  | -------- | -------- | -------- | -------- |
  | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the current location.|

**Example**

  ```ts
  import geolocation from '@ohos.geolocation';
  var locationChange = (err, location) => {
      if (err) {
          console.log('locationChanger: err=' + JSON.stringify(err));
      }
      if (location) {
          console.log('locationChanger: location=' + JSON.stringify(location));
      }
  };
Z
zengyawen 已提交
556 557 558 559
  geolocation.getCurrentLocation(locationChange);
  ```


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

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

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

S
shawn_he 已提交
566
> **NOTE**<br>
S
shawn_he 已提交
567 568 569
> 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 已提交
570

S
shawn_he 已提交
571
**System capability**: SystemCapability.Location.Location.Core
Z
zengyawen 已提交
572

L
liu-binjun 已提交
573 574
**Parameters**

575
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
576
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
577
  | request | [CurrentLocationRequest](#currentlocationrequest) | No| Location request.|
Z
zengyawen 已提交
578

L
liu-binjun 已提交
579 580
**Return value**

S
shawn_he 已提交
581 582 583
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;[Location](#location)&gt; |[Location](#location)|NA| Promise used to return the current location.|
S
shawn_he 已提交
584

Z
zengyawen 已提交
585

L
liu-binjun 已提交
586
**Example**
S
shawn_he 已提交
587 588

  ```ts
L
liu-binjun 已提交
589
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
590
  var requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
L
liu-binjun 已提交
591
  geolocation.getCurrentLocation(requestInfo).then((result) => {
Z
zengyawen 已提交
592 593 594 595 596
      console.log('current location: ' + JSON.stringify(result));
  });
  ```


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

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

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

S
shawn_he 已提交
603
> **NOTE**<br>
S
shawn_he 已提交
604 605 606
> 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 已提交
607 608

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

L
liu-binjun 已提交
610 611
**Parameters**

612
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
613
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
614 615
  | callback | AsyncCallback&lt;[Location](#location)&gt; | Yes| Callback used to return the previous location.|

Z
zengyawen 已提交
616

L
liu-binjun 已提交
617
**Example**
S
shawn_he 已提交
618 619

  ```ts
L
liu-binjun 已提交
620
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
621
  geolocation.getLastLocation((err, data) => {
L
liu-binjun 已提交
622 623 624 625 626 627
      if (err) {
          console.log('getLastLocation: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('getLastLocation: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
628 629 630 631
  });
  ```


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

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

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

S
shawn_he 已提交
638
> **NOTE**<br>
S
shawn_he 已提交
639 640 641
> 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 已提交
642 643 644

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

L
liu-binjun 已提交
645 646
**Return value**

S
shawn_he 已提交
647 648 649
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;[Location](#location)&gt; | [Location](#location)|NA|Promise used to return the previous location.|
S
shawn_he 已提交
650

Z
zengyawen 已提交
651

L
liu-binjun 已提交
652
**Example**
S
shawn_he 已提交
653 654

  ```ts
L
liu-binjun 已提交
655
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
656 657 658 659 660 661
  geolocation.getLastLocation().then((result) => {
      console.log('getLastLocation: result: ' + JSON.stringify(result));
  });
  ```


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

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

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

S
shawn_he 已提交
668
> **NOTE**<br>
S
shawn_he 已提交
669 670 671
> 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 已提交
672 673

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

L
liu-binjun 已提交
675 676
**Parameters**

677
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
678
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
679 680
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.|

L
liu-binjun 已提交
681
**Example**
S
shawn_he 已提交
682 683

  ```ts
L
liu-binjun 已提交
684
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
685
  geolocation.isLocationEnabled((err, data) => {
L
liu-binjun 已提交
686 687 688 689 690 691
      if (err) {
          console.log('isLocationEnabled: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('isLocationEnabled: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
692 693 694 695
  });
  ```


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

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

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

S
shawn_he 已提交
702
> **NOTE**<br>
S
shawn_he 已提交
703 704 705
> 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 已提交
706

S
shawn_he 已提交
707 708
**System capability**: SystemCapability.Location.Location.Core

L
liu-binjun 已提交
709 710
**Return value**

S
shawn_he 已提交
711 712 713
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;boolean&gt; | boolean|NA|Promise used to return the location service status.|
Z
zengyawen 已提交
714

L
liu-binjun 已提交
715
**Example**
S
shawn_he 已提交
716 717

  ```ts
L
liu-binjun 已提交
718
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
719
  geolocation.isLocationEnabled().then((result) => {
L
liu-binjun 已提交
720
      console.log('promise, isLocationEnabled: ' + JSON.stringify(result));
Z
zengyawen 已提交
721 722 723 724
  });
  ```


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

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

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

S
shawn_he 已提交
731
> **NOTE**<br>
S
shawn_he 已提交
732 733 734
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.requestEnableLocation](js-apis-geoLocationManager.md#geolocationmanagerrequestenablelocation).

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

S
shawn_he 已提交
736
**System capability**: SystemCapability.Location.Location.Core
Z
zengyawen 已提交
737

L
liu-binjun 已提交
738 739
**Parameters**

740
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
741
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
742 743
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the location service status.|

L
liu-binjun 已提交
744
**Example**
S
shawn_he 已提交
745 746

  ```ts
L
liu-binjun 已提交
747
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
748
  geolocation.requestEnableLocation((err, data) => {
L
liu-binjun 已提交
749 750 751 752 753 754
      if (err) {
          console.log('requestEnableLocation: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('requestEnableLocation: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
755 756 757 758
  });
  ```


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

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

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

S
shawn_he 已提交
765
> **NOTE**<br>
S
shawn_he 已提交
766
> This API is deprecated since API version 9. You are advised to use [geoLocationManager.requestEnableLocation](js-apis-geoLocationManager.md#geolocationmanagerrequestenablelocation-1).
S
shawn_he 已提交
767

S
shawn_he 已提交
768
**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
769 770 771

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

L
liu-binjun 已提交
772 773
**Return value**

774
  | Name| Type| Mandatory| Description|
S
shawn_he 已提交
775
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
776
  | Promise&lt;boolean&gt; | boolean|NA|Promise used to return the location service status.|
S
shawn_he 已提交
777

L
liu-binjun 已提交
778
**Example**
S
shawn_he 已提交
779

S
shawn_he 已提交
780
  ```ts
L
liu-binjun 已提交
781
  import geolocation from '@ohos.geolocation';
S
shawn_he 已提交
782 783
  geolocation.requestEnableLocation().then((result) => {
      console.log('promise, requestEnableLocation: ' + JSON.stringify(result));
S
shawn_he 已提交
784 785 786
  });
  ```

S
shawn_he 已提交
787 788

## geolocation.isGeoServiceAvailable<sup>(deprecated) </sup>
Z
zengyawen 已提交
789

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

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

S
shawn_he 已提交
794
> **NOTE**<br>
S
shawn_he 已提交
795 796 797
> 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 已提交
798 799

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

L
liu-binjun 已提交
801 802
**Parameters**

803
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
804
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
805 806
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the (reverse) geocoding service status.|

L
liu-binjun 已提交
807
**Example**
S
shawn_he 已提交
808 809

  ```ts
L
liu-binjun 已提交
810
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
811
  geolocation.isGeoServiceAvailable((err, data) => {
L
liu-binjun 已提交
812 813 814 815 816 817
      if (err) {
          console.log('isGeoServiceAvailable: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('isGeoServiceAvailable: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
818 819 820 821
  });
  ```


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

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

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

S
shawn_he 已提交
828
> **NOTE**<br>
S
shawn_he 已提交
829 830 831
> 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 已提交
832 833

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

L
liu-binjun 已提交
835 836
**Return value**

S
shawn_he 已提交
837 838 839
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;boolean&gt; |boolean|NA| Promise used to return the (reverse) geocoding service status.|
S
shawn_he 已提交
840

L
liu-binjun 已提交
841
**Example**
S
shawn_he 已提交
842 843

  ```ts
L
liu-binjun 已提交
844
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
845
  geolocation.isGeoServiceAvailable().then((result) => {
L
liu-binjun 已提交
846
      console.log('promise, isGeoServiceAvailable: ' + JSON.stringify(result));
Z
zengyawen 已提交
847 848 849 850
  });
  ```


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

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

S
shawn_he 已提交
855 856
Converts coordinates into geographic description through reverse geocoding. This API uses an asynchronous callback to return the result. 

S
shawn_he 已提交
857
> **NOTE**<br>
S
shawn_he 已提交
858 859 860
> 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 已提交
861 862

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

L
liu-binjun 已提交
864 865
**Parameters**

866
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
867
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
868 869
  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the reverse geocoding result.|
Z
zengyawen 已提交
870

L
liu-binjun 已提交
871
**Example**
S
shawn_he 已提交
872 873

  ```ts
L
liu-binjun 已提交
874
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
875 876
  var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
  geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
L
liu-binjun 已提交
877 878 879 880 881 882
      if (err) {
          console.log('getAddressesFromLocation: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('getAddressesFromLocation: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
883 884 885 886
  });
  ```


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

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

S
shawn_he 已提交
891 892
Converts coordinates into geographic description through reverse geocoding. This API uses a promise to return the result. 

S
shawn_he 已提交
893
> **NOTE**<br>
S
shawn_he 已提交
894 895 896
> 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 已提交
897 898

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

L
liu-binjun 已提交
900 901
**Parameters**

902
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
903
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
904
  | request | [ReverseGeoCodeRequest](#reversegeocoderequest) | Yes| Reverse geocoding request.|
Z
zengyawen 已提交
905

L
liu-binjun 已提交
906 907
**Return value**

S
shawn_he 已提交
908 909 910
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Array&lt;[GeoAddress](#geoaddress)&gt;|NA|Promise used to return the reverse geocoding result.|
Z
zengyawen 已提交
911

L
liu-binjun 已提交
912
**Example**
S
shawn_he 已提交
913 914

  ```ts
L
liu-binjun 已提交
915
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
916 917 918 919 920 921 922
  var reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
  geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
      console.log('getAddressesFromLocation: ' + JSON.stringify(data));
  });
  ```


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

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

S
shawn_he 已提交
927 928
Converts geographic description into coordinates through geocoding. This API uses an asynchronous callback to return the result. 

S
shawn_he 已提交
929
> **NOTE**<br>
S
shawn_he 已提交
930 931 932
> 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 已提交
933 934

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

L
liu-binjun 已提交
936 937
**Parameters**

938
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
939
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
940 941 942
  | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Yes| Callback used to return the geocoding result.|

L
liu-binjun 已提交
943
**Example**
S
shawn_he 已提交
944 945

  ```ts
L
liu-binjun 已提交
946
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
947 948
  var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
  geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => {
L
liu-binjun 已提交
949 950 951 952 953 954
      if (err) {
          console.log('getAddressesFromLocationName: err=' + JSON.stringify(err));
      }
      if (data) {
          console.log('getAddressesFromLocationName: data=' + JSON.stringify(data));
      }
Z
zengyawen 已提交
955 956 957 958
  });
  ```


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

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

S
shawn_he 已提交
963 964
Converts geographic description into coordinates through geocoding. This API uses a promise to return the result. 

S
shawn_he 已提交
965
> **NOTE**<br>
S
shawn_he 已提交
966 967 968
> 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 已提交
969 970

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

L
liu-binjun 已提交
972 973
**Parameters**

974
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
975
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
976
  | request | [GeoCodeRequest](#geocoderequest) | Yes| Geocoding request.|
Z
zengyawen 已提交
977

L
liu-binjun 已提交
978 979
**Return value**

S
shawn_he 已提交
980 981
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
982
  | Promise&lt;Array&lt;[GeoAddress](#geoaddress)&gt;&gt; | Array&lt;[GeoAddress](#geoaddress)&gt;|NA|Promise used to return the geocoding result.|
Z
zengyawen 已提交
983

L
liu-binjun 已提交
984
**Example**
S
shawn_he 已提交
985 986

  ```ts
L
liu-binjun 已提交
987
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
988 989 990 991 992 993 994
  var geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
  geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
      console.log('getAddressesFromLocationName: ' + JSON.stringify(result));
  });
  ```


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

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

S
shawn_he 已提交
999 1000
Obtains the number of cached GNSS locations. 

S
shawn_he 已提交
1001
> **NOTE**
S
shawn_he 已提交
1002
> 
S
shawn_he 已提交
1003 1004 1005 1006
> 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 已提交
1007 1008

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

L
liu-binjun 已提交
1010 1011
**Parameters**

1012
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
1013
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1014
  | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the number of cached GNSS locations. |
Z
zengyawen 已提交
1015

L
liu-binjun 已提交
1016
**Example**
S
shawn_he 已提交
1017 1018

  ```ts
L
liu-binjun 已提交
1019
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
1020
  geolocation.getCachedGnssLocationsSize((err, size) => {
L
liu-binjun 已提交
1021 1022 1023 1024 1025 1026
      if (err) {
          console.log('getCachedGnssLocationsSize: err=' + JSON.stringify(err));
      }
      if (size) {
          console.log('getCachedGnssLocationsSize: size=' + JSON.stringify(size));
      }
Z
zengyawen 已提交
1027 1028 1029 1030
  });
  ```


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

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

S
shawn_he 已提交
1035
Obtains the number of cached GNSS locations. 
Z
zengyawen 已提交
1036

S
shawn_he 已提交
1037
> **NOTE**
S
shawn_he 已提交
1038
> 
S
shawn_he 已提交
1039 1040 1041 1042
> 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 已提交
1043 1044 1045

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

L
liu-binjun 已提交
1046 1047
**Return value**

S
shawn_he 已提交
1048 1049 1050
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;number&gt; | number|NA|Promise used to return the number of cached GNSS locations.|
Z
zengyawen 已提交
1051

L
liu-binjun 已提交
1052
**Example**
S
shawn_he 已提交
1053 1054

  ```ts
L
liu-binjun 已提交
1055
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
1056
  geolocation.getCachedGnssLocationsSize().then((result) => {
L
liu-binjun 已提交
1057
      console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
Z
zengyawen 已提交
1058 1059 1060 1061
  });
  ```


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

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

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

S
shawn_he 已提交
1068
> **NOTE**
S
shawn_he 已提交
1069
> 
S
shawn_he 已提交
1070 1071 1072 1073
> 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 已提交
1074 1075

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

L
liu-binjun 已提交
1077 1078
**Parameters**

1079
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
1080
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1081
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the operation result.|
Z
zengyawen 已提交
1082

L
liu-binjun 已提交
1083
**Example**
S
shawn_he 已提交
1084 1085

  ```ts
L
liu-binjun 已提交
1086
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
1087
  geolocation.flushCachedGnssLocations((err, result) => {
L
liu-binjun 已提交
1088 1089 1090 1091 1092 1093
      if (err) {
          console.log('flushCachedGnssLocations: err=' + JSON.stringify(err));
      }
      if (result) {
          console.log('flushCachedGnssLocations: result=' + JSON.stringify(result));
      }
Z
zengyawen 已提交
1094 1095 1096 1097
  });
  ```


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

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

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

S
shawn_he 已提交
1104
> **NOTE**
S
shawn_he 已提交
1105
> 
S
shawn_he 已提交
1106 1107 1108 1109
> 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 已提交
1110 1111

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

L
liu-binjun 已提交
1113 1114
**Return value**

S
shawn_he 已提交
1115 1116 1117
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;boolean&gt; |boolean|NA| Promise used to return the operation result.|
Z
zengyawen 已提交
1118

L
liu-binjun 已提交
1119
**Example**
S
shawn_he 已提交
1120 1121

  ```ts
L
liu-binjun 已提交
1122
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
1123
  geolocation.flushCachedGnssLocations().then((result) => {
L
liu-binjun 已提交
1124
      console.log('promise, flushCachedGnssLocations: ' + JSON.stringify(result));
Z
zengyawen 已提交
1125 1126 1127 1128
  });
  ```


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

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

S
shawn_he 已提交
1133 1134 1135
Sends an extended command to the location subsystem. 

> **NOTE**
S
shawn_he 已提交
1136
> 
S
shawn_he 已提交
1137 1138
> 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 已提交
1139

S
shawn_he 已提交
1140
**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1141 1142

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

L
liu-binjun 已提交
1144 1145
**Parameters**

1146
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
1147
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1148
  | command |  [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
S
shawn_he 已提交
1149
  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the operation result.|
Z
zengyawen 已提交
1150

L
liu-binjun 已提交
1151
**Example**
S
shawn_he 已提交
1152 1153

  ```ts
L
liu-binjun 已提交
1154
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
1155 1156
  var requestInfo = {'scenario': 0x301, 'command': "command_1"};
  geolocation.sendCommand(requestInfo, (err, result) => {
L
liu-binjun 已提交
1157 1158 1159 1160 1161 1162
      if (err) {
          console.log('sendCommand: err=' + JSON.stringify(err));
      }
      if (result) {
          console.log('sendCommand: result=' + JSON.stringify(result));
      }
Z
zengyawen 已提交
1163 1164 1165 1166
  });
  ```


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

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

S
shawn_he 已提交
1171 1172 1173
Sends an extended command to the location subsystem. 

> **NOTE**
S
shawn_he 已提交
1174
> 
S
shawn_he 已提交
1175 1176
> 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 已提交
1177

S
shawn_he 已提交
1178
**Required permissions**: ohos.permission.LOCATION
S
shawn_he 已提交
1179 1180

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

L
liu-binjun 已提交
1182 1183
**Parameters**

1184
  | Name| Type| Mandatory| Description|
Z
zengyawen 已提交
1185
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1186
  | command | [LocationCommand](#locationcommand) | Yes| Extended command (string) to be sent.|
Z
zengyawen 已提交
1187

L
liu-binjun 已提交
1188 1189
**Return value**

S
shawn_he 已提交
1190 1191 1192
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | Promise&lt;boolean&gt; |boolean|NA| Callback used to return the operation result.|
Z
zengyawen 已提交
1193

L
liu-binjun 已提交
1194
**Example**
S
shawn_he 已提交
1195 1196

  ```ts
L
liu-binjun 已提交
1197
  import geolocation from '@ohos.geolocation';
Z
zengyawen 已提交
1198 1199
  var requestInfo = {'scenario': 0x301, 'command': "command_1"};
  geolocation.sendCommand(requestInfo).then((result) => {
L
liu-binjun 已提交
1200
      console.log('promise, sendCommand: ' + JSON.stringify(result));
Z
zengyawen 已提交
1201 1202 1203 1204
  });
  ```


S
shawn_he 已提交
1205
## LocationRequestPriority<sup>(deprecated) </sup>
S
shawn_he 已提交
1206

L
liu-binjun 已提交
1207
Sets the priority of the location request.
S
shawn_he 已提交
1208

S
shawn_he 已提交
1209
> **NOTE**<br>
S
shawn_he 已提交
1210 1211 1212
> 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
S
shawn_he 已提交
1213 1214

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

S
shawn_he 已提交
1216
| Name| Value| Description|
L
liu-binjun 已提交
1217 1218 1219 1220 1221
| -------- | -------- | -------- |
| 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.|
L
liu-binjun 已提交
1222

Z
zengyawen 已提交
1223

S
shawn_he 已提交
1224
## LocationRequestScenario<sup>(deprecated) </sup>
L
liu-binjun 已提交
1225 1226 1227

  Sets the scenario of the location request.

S
shawn_he 已提交
1228
> **NOTE**<br>
S
shawn_he 已提交
1229 1230 1231
> 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
Z
zengyawen 已提交
1232

L
liu-binjun 已提交
1233
**System capability**: SystemCapability.Location.Location.Core
Z
zengyawen 已提交
1234

S
shawn_he 已提交
1235
| Name| Value| Description|
L
liu-binjun 已提交
1236 1237 1238 1239 1240 1241 1242
| -------- | -------- | -------- |
| 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.|
Z
zengyawen 已提交
1243 1244


S
shawn_he 已提交
1245
## GeoLocationErrorCode<sup>(deprecated) </sup>
S
shawn_he 已提交
1246

L
liu-binjun 已提交
1247
Enumerates error codes of the location service.
S
shawn_he 已提交
1248

S
shawn_he 已提交
1249
> **NOTE**<br>
S
shawn_he 已提交
1250 1251 1252
> This API is deprecated since API version 9.

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

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

S
shawn_he 已提交
1256
| Name| Value| Description|
L
liu-binjun 已提交
1257 1258 1259 1260 1261 1262 1263 1264
| -------- | -------- | -------- |
| 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.|
L
liu-binjun 已提交
1265

Z
zengyawen 已提交
1266

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

L
liu-binjun 已提交
1269
Defines a reverse geocoding request.
Z
zengyawen 已提交
1270

S
shawn_he 已提交
1271
> **NOTE**<br>
S
shawn_he 已提交
1272 1273 1274
> 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 已提交
1275

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

S
shawn_he 已提交
1278 1279 1280 1281
| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
| latitude | number | Yes| Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
S
shawn_he 已提交
1282
| longitude | number | Yes| Yes| Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
S
shawn_he 已提交
1283
| maxItems | number | Yes| Yes| Maximum number of location records to be returned.|
Z
zengyawen 已提交
1284 1285


S
shawn_he 已提交
1286
## GeoCodeRequest<sup>(deprecated) </sup>
S
shawn_he 已提交
1287

L
liu-binjun 已提交
1288
Defines a geocoding request.
S
shawn_he 已提交
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.GeoCodeRequest](js-apis-geoLocationManager.md#geocoderequest).

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

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

S
shawn_he 已提交
1297 1298 1299 1300 1301 1302 1303 1304 1305
| 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**.|
| maxItems | number | Yes| Yes| Maximum number of location records to be returned.|
| minLatitude | number | Yes| Yes| Minimum latitude. This parameter is used with **minLongitude**, **maxLatitude**, and **maxLongitude** to specify the latitude and longitude ranges.|
| minLongitude | number | Yes| Yes| Minimum longitude.|
| maxLatitude | number | Yes| Yes| Maximum latitude.|
| maxLongitude | number | Yes| Yes| Maximum longitude.|
L
liu-binjun 已提交
1306

Z
zengyawen 已提交
1307

S
shawn_he 已提交
1308
## GeoAddress<sup>(deprecated) </sup>
L
liu-binjun 已提交
1309 1310 1311

Defines a geographic location.

S
shawn_he 已提交
1312
> **NOTE**<br>
S
shawn_he 已提交
1313 1314 1315
> 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 已提交
1316

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

S
shawn_he 已提交
1319 1320 1321
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| latitude<sup>7+</sup> | number | Yes| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
S
shawn_he 已提交
1322
| longitude<sup>7+</sup> | number | Yes| No| Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
S
shawn_he 已提交
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341
| 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.|
| descriptionsSize<sup>7+</sup> | number | Yes| No| Total number of additional descriptions.|


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

L
liu-binjun 已提交
1343
Defines a location request.
S
shawn_he 已提交
1344

S
shawn_he 已提交
1345
> **NOTE**<br>
S
shawn_he 已提交
1346 1347 1348
> 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 已提交
1349 1350

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

S
shawn_he 已提交
1352 1353 1354 1355 1356 1357 1358
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request.|
| timeInterval | number | Yes| Yes| Time interval at which location information is reported.|
| distanceInterval | number | Yes| Yes| Distance interval at which location information is reported.|
| maxAccuracy | number | Yes| Yes| Location accuracy. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled.|
L
liu-binjun 已提交
1359

Z
zengyawen 已提交
1360

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

L
liu-binjun 已提交
1363
Defines the current location request.
Z
zengyawen 已提交
1364

S
shawn_he 已提交
1365
> **NOTE**<br>
S
shawn_he 已提交
1366 1367 1368
> 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 已提交
1369

L
liu-binjun 已提交
1370
**System capability**: SystemCapability.Location.Location.Core
L
liu-binjun 已提交
1371

S
shawn_he 已提交
1372 1373 1374 1375 1376 1377
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes| Priority of the location request.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes| Scenario of the location request.|
| maxAccuracy | number | Yes| Yes| Location accuracy, in meters. This parameter is valid only when the precise location function is enabled, and is invalid when the approximate location function is enabled.|
| timeoutMs | number | Yes| Yes| Timeout duration, in milliseconds. The minimum value is **1000**.|
L
liu-binjun 已提交
1378 1379


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

L
liu-binjun 已提交
1382
Defines the satellite status information.
L
liu-binjun 已提交
1383

S
shawn_he 已提交
1384
> **NOTE**
S
shawn_he 已提交
1385
> 
S
shawn_he 已提交
1386 1387 1388 1389
> 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 已提交
1390

L
liu-binjun 已提交
1391
**System capability**: SystemCapability.Location.Location.Gnss
L
liu-binjun 已提交
1392

S
shawn_he 已提交
1393 1394 1395 1396 1397 1398 1399 1400
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| satellitesNumber | number | Yes| No| Number of satellites.|
| satelliteIds | Array&lt;number&gt; | Yes| No| Array of satellite IDs.|
| carrierToNoiseDensitys | Array&lt;number&gt; | Yes| No| Carrier-to-noise density ratio, that is, **cn0**.|
| altitudes | Array&lt;number&gt; | Yes| No| Altitude information.|
| azimuths | Array&lt;number&gt; | Yes| No| Azimuth information.|
| carrierFrequencies | Array&lt;number&gt; | Yes| No| Carrier frequency.|
L
liu-binjun 已提交
1401 1402


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

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

S
shawn_he 已提交
1407
> **NOTE**
S
shawn_he 已提交
1408
> 
S
shawn_he 已提交
1409 1410 1411 1412
> 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 已提交
1413

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

S
shawn_he 已提交
1416 1417 1418 1419
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| reportingPeriodSec | number | Yes| Yes| Interval for reporting the cached GNSS locations, in milliseconds.|
| wakeUpCacheQueueFull | boolean | Yes| Yes | **true**: reports the cached GNSS locations to the application when the cache queue is full.<br>**false**: discards the cached GNSS locations when the cache queue is full.|
Z
zengyawen 已提交
1420 1421


S
shawn_he 已提交
1422
## Geofence<sup>(deprecated) </sup>
Z
zengyawen 已提交
1423 1424 1425

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

S
shawn_he 已提交
1426
> **NOTE**
S
shawn_he 已提交
1427
> 
S
shawn_he 已提交
1428 1429 1430 1431
> 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 已提交
1432 1433 1434

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

S
shawn_he 已提交
1435 1436 1437 1438 1439 1440
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| latitude | number | Yes| Yes | Latitude information.|
| longitude | number | Yes| Yes | Longitude information.|
| radius | number | Yes| Yes | Radius of a circular geofence.|
| expiration | number | Yes| Yes | Expiration period of a geofence, in milliseconds.|
Z
zengyawen 已提交
1441 1442


S
shawn_he 已提交
1443
## GeofenceRequest<sup>(deprecated) </sup>
Z
zengyawen 已提交
1444 1445 1446

Represents a GNSS geofencing request.

S
shawn_he 已提交
1447
> **NOTE**
S
shawn_he 已提交
1448
> 
S
shawn_he 已提交
1449 1450 1451 1452
> 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 已提交
1453 1454 1455

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

S
shawn_he 已提交
1456 1457 1458 1459 1460
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| priority | [LocationRequestPriority](#locationrequestpriority) | Yes| Yes | Priority of the location information.|
| scenario | [LocationRequestScenario](#locationrequestscenario) | Yes| Yes | Location scenario.|
| geofence | [Geofence](#geofence)| Yes| Yes | Geofence information.|
Z
zengyawen 已提交
1461 1462


S
shawn_he 已提交
1463
## LocationPrivacyType<sup>(deprecated) </sup>
Z
zengyawen 已提交
1464 1465 1466

Defines the privacy statement type.

S
shawn_he 已提交
1467
> **NOTE**
S
shawn_he 已提交
1468
> 
S
shawn_he 已提交
1469 1470 1471 1472
> 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
S
shawn_he 已提交
1473 1474 1475

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

S
shawn_he 已提交
1476
| Name| Value| Description|
Z
zengyawen 已提交
1477
| -------- | -------- | -------- |
S
shawn_he 已提交
1478 1479 1480
| OTHERS | 0 | Other scenarios.|
| STARTUP | 1 | Privacy statement displayed in the startup wizard.|
| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.|
Z
zengyawen 已提交
1481 1482


S
shawn_he 已提交
1483
## LocationCommand<sup>(deprecated) </sup>
Z
zengyawen 已提交
1484 1485 1486

Defines an extended command.

S
shawn_he 已提交
1487
> **NOTE**
S
shawn_he 已提交
1488
> 
S
shawn_he 已提交
1489 1490 1491 1492
> 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 已提交
1493 1494 1495

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

S
shawn_he 已提交
1496 1497 1498 1499
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| scenario | [LocationRequestScenario](#locationrequestscenario)  | Yes| Yes | Location scenario.|
| command | string | Yes| Yes | Extended command, in the string format.|
Z
zengyawen 已提交
1500 1501


S
shawn_he 已提交
1502
## Location<sup>(deprecated) </sup>
Z
zengyawen 已提交
1503 1504 1505

Defines a location.

S
shawn_he 已提交
1506
> **NOTE**<br>
S
shawn_he 已提交
1507 1508 1509
> 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 已提交
1510 1511 1512

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

S
shawn_he 已提交
1513 1514 1515
| Name| Type| Readable|Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| latitude<sup>7+</sup> | number | Yes| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude.|
S
shawn_he 已提交
1516
| longitude<sup>7+</sup> | number | Yes| No| Longitude information. A positive value indicates east longitude, and a negative value indicates west longitude.|
S
shawn_he 已提交
1517 1518 1519 1520 1521 1522 1523 1524
| 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.|
| direction<sup>7+</sup> | number | Yes| No| Direction information.|
| timeSinceBoot<sup>7+</sup> | number | Yes| No| Location timestamp since boot.|
| additions<sup>7+</sup> | Array&lt;string&gt; | Yes| No| Additional description.|
| additionSize<sup>7+</sup> | number | Yes| No| Number of additional descriptions.|