1# @ohos.geolocation (Geolocation)
2
3The **geolocation** module provides a wide array of location services, including GNSS positioning, network positioning, geocoding, reverse geocoding, and geofencing.
4
5> **NOTE**
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.
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).
8> This module supports only the WGS-84 coordinate system.
9
10## Applying for Permissions
11
12Before 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.
13
14The system provides the following location permissions:
15- ohos.permission.LOCATION
16
17- ohos.permission.APPROXIMATELY_LOCATION
18
19- ohos.permission.LOCATION_IN_BACKGROUND
20
21If your application needs to access the device location information, it must first apply for required permissions. Specifically speaking:
22
23API versions earlier than 9: Apply for **ohos.permission.LOCATION**.
24
25API 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.
26
27| API Version| Location Permission| Permission Application Result| Location Accuracy|
28| -------- | -------- | -------- | -------- |
29| Earlier than 9| ohos.permission.LOCATION | Successful| Location accurate to meters.|
30| 9 and later| ohos.permission.LOCATION | Failed| No location obtained.|
31| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Successful| Location accurate to 5 kilometers.|
32| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Successful| Location accurate to meters.|
33
34To access the device location information when running in the background, an application needs to request for a continuous task of the LOCATION type. In this way, the system continues to report device location information after your application moves to the background. For details about how to request for a continuous task, see [Continuous Task](../../task-management/continuous-task.md).
35
36A user can grant the **ohos.permission.LOCATION_IN_BACKGROUND** permission for an application on the setting page. For details, see [ohos.permission.LOCATION_IN_BACKGROUND](../../security/AccessToken/permissions-for-all.md#ohospermissionlocation_in_background).
37
38You can declare the required permission in your application's configuration file. For details, see [Requesting User Authorization](../../security/AccessToken/request-user-authorization.md).
39
40
41## Modules to Import
42
43```ts
44import geolocation from '@ohos.geolocation';
45```
46
47## geolocation.on('locationChange')<sup>(deprecated)</sup>
48
49on(type: 'locationChange', request: LocationRequest, callback: Callback&lt;Location&gt;): void
50
51Registers a listener for location changes with a location request initiated. This API uses an asynchronous callback to return the result.
52
53> **NOTE**<br>
54> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('locationChange')](js-apis-geoLocationManager.md#geolocationmanageronlocationchange).
55
56**Required permissions**: ohos.permission.LOCATION
57
58**System capability**: SystemCapability.Location.Location.Core
59
60**Parameters**
61
62  | Name| Type| Mandatory| Description|
63  | -------- | -------- | -------- | -------- |
64  | type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
65  | request |  [LocationRequest](#locationrequestdeprecated) | Yes| Location request.|
66  | callback | Callback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to return the result.|
67
68
69
70**Example**
71
72  ```ts
73  import geolocation from '@ohos.geolocation';
74  let requestInfo:geolocation.LocationRequest = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
75  let locationChange = (location:geolocation.Location):void => {
76      console.info('locationChanger: data: ' + JSON.stringify(location));
77  };
78  geolocation.on('locationChange', requestInfo, locationChange);
79  ```
80
81
82## geolocation.off('locationChange')<sup>(deprecated)</sup>
83
84off(type: 'locationChange', callback?: Callback&lt;Location&gt;): void
85
86Unregisters the listener for location changes with the corresponding location request deleted.
87
88> **NOTE**<br>
89> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('locationChange')](js-apis-geoLocationManager.md#geolocationmanagerofflocationchange).
90
91**Required permissions**: ohos.permission.LOCATION
92
93**System capability**: SystemCapability.Location.Location.Core
94
95**Parameters**
96
97  | Name| Type| Mandatory| Description|
98  | -------- | -------- | -------- | -------- |
99  | type | string | Yes| Event type. The value **locationChange** indicates a location change event.|
100  | callback | Callback&lt;[Location](#locationdeprecated)&gt; | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
101
102
103**Example**
104
105  ```ts
106  import geolocation from '@ohos.geolocation';
107  let requestInfo:geolocation.LocationRequest = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0};
108  let locationChange = (location:geolocation.Location):void => {
109      console.info('locationChanger: data: ' + JSON.stringify(location));
110  };
111  geolocation.on('locationChange', requestInfo, locationChange);
112  geolocation.off('locationChange', locationChange);
113  ```
114
115
116## geolocation.on('locationServiceState')<sup>(deprecated)</sup>
117
118on(type: 'locationServiceState', callback: Callback&lt;boolean&gt;): void
119
120Registers a listener for location service status change events. This API uses an asynchronous callback to return the result.
121
122> **NOTE**<br>
123> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('locationEnabledChange')](js-apis-geoLocationManager.md#geolocationmanageronlocationenabledchange).
124
125**Required permissions**: ohos.permission.LOCATION
126
127**System capability**: SystemCapability.Location.Location.Core
128
129**Parameters**
130
131  | Name| Type| Mandatory| Description|
132  | -------- | -------- | -------- | -------- |
133  | type | string | Yes| Event type. The value **locationServiceState** indicates a location service status change event.|
134  | callback | Callback&lt;boolean&gt; | Yes| Callback used to return the result. The value **true** indicates that the location service is enabled, and the value **false** indicates the opposite.|
135
136
137**Example**
138
139  ```ts
140  import geolocation from '@ohos.geolocation';
141  let locationServiceState = (state:boolean):void => {
142      console.info('locationServiceState: ' + JSON.stringify(state));
143  }
144  geolocation.on('locationServiceState', locationServiceState);
145  ```
146
147
148## geolocation.off('locationServiceState')<sup>(deprecated)</sup>
149
150off(type: 'locationServiceState', callback?: Callback&lt;boolean&gt;): void
151
152Unregisters the listener for location service status change events.
153
154> **NOTE**<br>
155> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('locationEnabledChange')](js-apis-geoLocationManager.md#geolocationmanagerofflocationenabledchange).
156
157**Required permissions**: ohos.permission.LOCATION
158
159**System capability**: SystemCapability.Location.Location.Core
160
161**Parameters**
162
163  | Name| Type| Mandatory| Description|
164  | -------- | -------- | -------- | -------- |
165  | type | string | Yes| Event type. The value **locationServiceState** indicates a location service status change event.|
166  | callback | Callback&lt;boolean&gt; | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
167
168
169**Example**
170
171  ```ts
172  import geolocation from '@ohos.geolocation';
173  let locationServiceState = (state:boolean):void => {
174      console.info('locationServiceState: state: ' + JSON.stringify(state));
175  }
176  geolocation.on('locationServiceState', locationServiceState);
177  geolocation.off('locationServiceState', locationServiceState);
178  ```
179
180
181## geolocation.on('cachedGnssLocationsReporting')<sup>(deprecated)</sup>
182
183on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, callback: Callback&lt;Array&lt;Location&gt;&gt;): void
184
185Registers a listener for cached GNSS location reports. This API uses an asynchronous callback to return the result.
186
187> **NOTE**<br>
188> This API is supported since API version 8.
189> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('cachedGnssLocationsChange')](js-apis-geoLocationManager.md#geolocationmanageroncachedgnsslocationschange).
190
191**Required permissions**: ohos.permission.LOCATION
192
193**System capability**: SystemCapability.Location.Location.Gnss
194
195**Parameters**
196
197  | Name| Type| Mandatory| Description|
198  | -------- | -------- | -------- | -------- |
199  | type | string | Yes| Event type. The value **cachedGnssLocationsReporting** indicates reporting of cached GNSS locations.|
200  | request |  [CachedGnssLocationsRequest](#cachedgnsslocationsrequestdeprecated) | Yes| Request for reporting cached GNSS location.|
201  | callback | Callback&lt;Array&lt;[Location](#locationdeprecated)&gt;&gt; | Yes| Callback used to return the result.|
202
203
204**Example**
205
206  ```ts
207  import geolocation from '@ohos.geolocation';
208  let cachedLocationsCb = (locations:Array<geolocation.Location>):void => {
209      console.info('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
210  }
211  let requestInfo:geolocation.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
212  geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
213  ```
214
215
216## geolocation.off('cachedGnssLocationsReporting')<sup>(deprecated)</sup>
217
218off(type: 'cachedGnssLocationsReporting', callback?: Callback&lt;Array&lt;Location&gt;&gt;): void
219
220Unregisters the listener for cached GNSS location reports.
221
222> **NOTE**<br>
223> This API is supported since API version 8.
224> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('cachedGnssLocationsChange')](js-apis-geoLocationManager.md#geolocationmanageroffcachedgnsslocationschange).
225
226**Required permissions**: ohos.permission.LOCATION
227
228**System capability**: SystemCapability.Location.Location.Gnss
229
230**Parameters**
231
232  | Name| Type| Mandatory| Description|
233  | -------- | -------- | -------- | -------- |
234  | type | string | Yes| Event type. The value **cachedGnssLocationsReporting** indicates reporting of cached GNSS locations.|
235  | callback | Callback&lt;Array&lt;[Location](#locationdeprecated)&gt;&gt; | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
236
237
238**Example**
239
240  ```ts
241  import geolocation from '@ohos.geolocation';
242  let cachedLocationsCb = (locations:Array<geolocation.Location>):void => {
243      console.info('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations));
244  }
245  let requestInfo:geolocation.CachedGnssLocationsRequest = {'reportingPeriodSec': 10, 'wakeUpCacheQueueFull': true};
246  geolocation.on('cachedGnssLocationsReporting', requestInfo, cachedLocationsCb);
247  geolocation.off('cachedGnssLocationsReporting');
248  ```
249
250
251## geolocation.on('gnssStatusChange')<sup>(deprecated)</sup>
252
253on(type: 'gnssStatusChange', callback: Callback&lt;SatelliteStatusInfo&gt;): void
254
255Registers a listener for GNSS satellite status change events. This API uses an asynchronous callback to return the result.
256
257> **NOTE**<br>
258> This API is supported since API version 8.
259> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('satelliteStatusChange')](js-apis-geoLocationManager.md#geolocationmanageronsatellitestatuschange).
260
261**Required permissions**: ohos.permission.LOCATION
262
263**System capability**: SystemCapability.Location.Location.Gnss
264
265**Parameters**
266
267  | Name| Type| Mandatory| Description|
268  | -------- | -------- | -------- | -------- |
269  | type | string | Yes| Event type. The value **gnssStatusChange** indicates a GNSS satellite status change.|
270  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfodeprecated)&gt; | Yes| Callback used to return the result.|
271
272
273**Example**
274
275  ```ts
276  import geolocation from '@ohos.geolocation';
277  let gnssStatusCb = (satelliteStatusInfo:geolocation.SatelliteStatusInfo):void => {
278      console.info('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
279  }
280  geolocation.on('gnssStatusChange', gnssStatusCb);
281  ```
282
283
284## geolocation.off('gnssStatusChange')<sup>(deprecated)</sup>
285
286off(type: 'gnssStatusChange', callback?: Callback&lt;SatelliteStatusInfo&gt;): void
287
288Unregisters the listener for GNSS satellite status change events.
289
290> **NOTE**<br>
291> This API is supported since API version 8.
292> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('satelliteStatusChange')](js-apis-geoLocationManager.md#geolocationmanageroffsatellitestatuschange).
293
294**Required permissions**: ohos.permission.LOCATION
295
296**System capability**: SystemCapability.Location.Location.Gnss
297
298**Parameters**
299
300  | Name| Type| Mandatory| Description|
301  | -------- | -------- | -------- | -------- |
302  | type | string | Yes| Event type. The value **gnssStatusChange** indicates a GNSS satellite status change.|
303  | callback | Callback&lt;[SatelliteStatusInfo](#satellitestatusinfodeprecated)&gt; | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
304
305**Example**
306
307  ```ts
308  import geolocation from '@ohos.geolocation';
309  let gnssStatusCb = (satelliteStatusInfo:geolocation.SatelliteStatusInfo) => {
310      console.info('gnssStatusChange: ' + JSON.stringify(satelliteStatusInfo));
311  }
312  geolocation.on('gnssStatusChange', gnssStatusCb);
313  geolocation.off('gnssStatusChange', gnssStatusCb);
314  ```
315
316
317## geolocation.on('nmeaMessageChange')<sup>(deprecated)</sup>
318
319on(type: 'nmeaMessageChange', callback: Callback&lt;string&gt;): void
320
321Registers a listener for GNSS NMEA message change events. This API uses an asynchronous callback to return the result.
322
323> **NOTE**<br>
324> This API is supported since API version 8.
325> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('nmeaMessage')](js-apis-geoLocationManager.md#geolocationmanageronnmeamessage).
326
327**Required permissions**: ohos.permission.LOCATION
328
329**System capability**: SystemCapability.Location.Location.Gnss
330
331**Parameters**
332
333  | Name| Type| Mandatory| Description|
334  | -------- | -------- | -------- | -------- |
335  | type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.|
336  | callback | Callback&lt;string&gt; | Yes| Callback used to return the result.|
337
338
339**Example**
340
341  ```ts
342  import geolocation from '@ohos.geolocation';
343  let nmeaCb = (str:string):void => {
344      console.info('nmeaMessageChange: ' + JSON.stringify(str));
345  }
346  geolocation.on('nmeaMessageChange', nmeaCb );
347  ```
348
349
350## geolocation.off('nmeaMessageChange')<sup>(deprecated)</sup>
351
352off(type: 'nmeaMessageChange', callback?: Callback&lt;string&gt;): void
353
354Unregisters the listener for GNSS NMEA message change events.
355
356> **NOTE**<br>
357> This API is supported since API version 8.
358> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('nmeaMessage')](js-apis-geoLocationManager.md#geolocationmanageroffnmeamessage).
359
360**Required permissions**: ohos.permission.LOCATION
361
362**System capability**: SystemCapability.Location.Location.Gnss
363
364**Parameters**
365
366  | Name| Type| Mandatory| Description|
367  | -------- | -------- | -------- | -------- |
368  | type | string | Yes| Event type. The value **nmeaMessageChange** indicates a GNSS NMEA message change.|
369  | callback | Callback&lt;string&gt; | No| Callback to unregister. The callback must be the same as that passed by the **on** API. If this parameter is not specified, all callbacks of the specified event type are unregistered.|
370
371
372**Example**
373
374  ```ts
375  import geolocation from '@ohos.geolocation';
376  let nmeaCb = (str:string):void => {
377      console.info('nmeaMessageChange: ' + JSON.stringify(str));
378  }
379  geolocation.on('nmeaMessageChange', nmeaCb);
380  geolocation.off('nmeaMessageChange', nmeaCb);
381  ```
382
383
384## geolocation.on('fenceStatusChange')<sup>(deprecated)</sup>
385
386on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void
387
388Registers a listener for status change events of the specified geofence. This API uses an asynchronous callback to return the result.
389
390> **NOTE**<br>
391> This API is supported since API version 8.
392> This API is deprecated since API version 9. You are advised to use [geoLocationManager.on('gnssFenceStatusChange')](js-apis-geoLocationManager.md#geolocationmanagerongnssfencestatuschange).
393
394**Required permissions**: ohos.permission.LOCATION
395
396**System capability**: SystemCapability.Location.Location.Geofence
397
398**Parameters**
399
400  | Name| Type| Mandatory| Description|
401  | -------- | -------- | -------- | -------- |
402  | type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.|
403  | request |  [GeofenceRequest](#geofencerequestdeprecated) | Yes| Geofencing request.|
404  | want | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
405
406**Example**
407
408  ```ts
409  import geolocation from '@ohos.geolocation';
410  import wantAgent from '@ohos.app.ability.wantAgent';
411
412  let wantAgentInfo:wantAgent.WantAgentInfo = {
413      wants: [
414          {
415              bundleName: "com.example.myapplication",
416              abilityName: "EntryAbility",
417              action: "action1"
418          }
419      ],
420      operationType: wantAgent.OperationType.START_ABILITY,
421      requestCode: 0,
422      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG],
423  };
424
425  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
426    let requestInfo:geolocation.GeofenceRequest = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 31.12, "longitude": 121.11, "radius": 100, "expiration": 10000}};
427    geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
428  });
429  ```
430
431
432## geolocation.off('fenceStatusChange')<sup>(deprecated)</sup>
433
434off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void
435
436Unregisters the listener for status change events of the specified geofence.
437
438> **NOTE**<br>
439> This API is supported since API version 8.
440> This API is deprecated since API version 9. You are advised to use [geoLocationManager.off('gnssFenceStatusChange')](js-apis-geoLocationManager.md#geolocationmanageroffgnssfencestatuschange).
441
442**Required permissions**: ohos.permission.LOCATION
443
444**System capability**: SystemCapability.Location.Location.Geofence
445
446**Parameters**
447
448  | Name| Type| Mandatory| Description|
449  | -------- | -------- | -------- | -------- |
450  | type | string | Yes| Event type. The value **fenceStatusChange** indicates a geofence status change.|
451  | request | [GeofenceRequest](#geofencerequestdeprecated) | Yes| Geofencing request.|
452  | want | [WantAgent](../apis-ability-kit/js-apis-app-ability-wantAgent.md) | Yes| **WantAgent** used to receive geofence (entrance or exit) events.|
453
454**Example**
455
456  ```ts
457  import geolocation from '@ohos.geolocation';
458  import wantAgent from '@ohos.app.ability.wantAgent';
459
460  let wantAgentInfo:wantAgent.WantAgentInfo = {
461      wants: [
462          {
463              bundleName: "com.example.myapplication",
464              abilityName: "EntryAbility",
465              action: "action1",
466          }
467      ],
468      operationType: wantAgent.OperationType.START_ABILITY,
469      requestCode: 0,
470      wantAgentFlags: [wantAgent.WantAgentFlags.UPDATE_PRESENT_FLAG]
471  };
472
473  wantAgent.getWantAgent(wantAgentInfo).then((wantAgentObj) => {
474    let requestInfo:geolocation.GeofenceRequest = {'priority': 0x201, 'scenario': 0x301, "geofence": {"latitude": 31.12, "longitude": 121.11, "radius": 100, "expiration": 10000}};
475    geolocation.on('fenceStatusChange', requestInfo, wantAgentObj);
476    geolocation.off('fenceStatusChange', requestInfo, wantAgentObj);
477  });
478  ```
479
480
481## geolocation.getCurrentLocation<sup>(deprecated)</sup>
482
483getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback&lt;Location&gt;): void
484
485Obtains the current position. This API uses an asynchronous callback to return the result.
486
487> **NOTE**<br>
488> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCurrentLocation](js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation).
489
490**Required permissions**: ohos.permission.LOCATION
491
492**System capability**: SystemCapability.Location.Location.Core
493
494**Parameters**
495
496  | Name| Type| Mandatory| Description|
497  | -------- | -------- | -------- | -------- |
498  | request | [CurrentLocationRequest](#currentlocationrequestdeprecated) | Yes| Location request.|
499  | callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to return the result.|
500
501**Example**
502
503  ```ts
504  import geolocation from '@ohos.geolocation';
505  import BusinessError from "@ohos.base"
506  let requestInfo:geolocation.CurrentLocationRequest = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
507  let locationChange = (err:BusinessError.BusinessError, location:geolocation.Location) => {
508      if (err) {
509          console.info('locationChanger: err=' + JSON.stringify(err));
510      }
511      if (location) {
512          console.info('locationChanger: location=' + JSON.stringify(location));
513      }
514  };
515  geolocation.getCurrentLocation(requestInfo, locationChange);
516  ```
517
518
519## geolocation.getCurrentLocation<sup>(deprecated)</sup>
520
521getCurrentLocation(callback: AsyncCallback&lt;Location&gt;): void
522
523
524Obtains the current position. This API uses an asynchronous callback to return the result.
525
526> **NOTE**<br>
527> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCurrentLocation](js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation).
528
529**Required permissions**: ohos.permission.LOCATION
530
531**System capability**: SystemCapability.Location.Location.Core
532
533**Parameters**
534
535  | Name| Type| Mandatory| Description|
536  | -------- | -------- | -------- | -------- |
537  | callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to return the result.|
538
539**Example**
540
541  ```ts
542  import geolocation from '@ohos.geolocation';
543  import BusinessError from "@ohos.base"
544  let locationChange = (err:BusinessError.BusinessError, location:geolocation.Location):void => {
545      if (err) {
546          console.info('locationChanger: err=' + JSON.stringify(err));
547      }
548      if (location) {
549          console.info('locationChanger: location=' + JSON.stringify(location));
550      }
551  };
552  geolocation.getCurrentLocation(locationChange);
553  ```
554
555
556## geolocation.getCurrentLocation<sup>(deprecated)</sup>
557
558getCurrentLocation(request?: CurrentLocationRequest): Promise&lt;Location&gt;
559
560Obtains the current position. This API uses a promise to return the result.
561
562> **NOTE**<br>
563> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCurrentLocation](js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation-2).
564
565**Required permissions**: ohos.permission.LOCATION
566
567**System capability**: SystemCapability.Location.Location.Core
568
569**Parameters**
570
571  | Name| Type| Mandatory| Description|
572  | -------- | -------- | -------- | -------- |
573  | request | [CurrentLocationRequest](#currentlocationrequestdeprecated) | No| Location request.|
574
575**Return value**
576
577  | Type| Description|
578  | -------- | -------- |
579  | Promise&lt;[Location](#locationdeprecated)&gt; | Promise used to return the result.|
580
581
582**Example**
583
584  ```ts
585  import geolocation from '@ohos.geolocation';
586  let requestInfo:geolocation.CurrentLocationRequest = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0};
587  geolocation.getCurrentLocation(requestInfo).then((result) => {
588      console.info('current location: ' + JSON.stringify(result));
589  });
590  ```
591
592
593## geolocation.getLastLocation<sup>(deprecated)</sup>
594
595getLastLocation(callback: AsyncCallback&lt;Location&gt;): void
596
597Obtains the previous location. This API uses an asynchronous callback to return the result.
598
599> **NOTE**<br>
600> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getLastLocation](js-apis-geoLocationManager.md#geolocationmanagergetlastlocation).
601
602**Required permissions**: ohos.permission.LOCATION
603
604**System capability**: SystemCapability.Location.Location.Core
605
606**Parameters**
607
608  | Name| Type| Mandatory| Description|
609  | -------- | -------- | -------- | -------- |
610  | callback | AsyncCallback&lt;[Location](#locationdeprecated)&gt; | Yes| Callback used to return the result.|
611
612
613**Example**
614
615  ```ts
616  import geolocation from '@ohos.geolocation';
617  geolocation.getLastLocation((err, data) => {
618      if (err) {
619          console.info('getLastLocation: err=' + JSON.stringify(err));
620      }
621      if (data) {
622          console.info('getLastLocation: data=' + JSON.stringify(data));
623      }
624  });
625  ```
626
627
628## geolocation.getLastLocation<sup>(deprecated)</sup>
629
630getLastLocation(): Promise&lt;Location&gt;
631
632Obtains the previous location. This API uses a promise to return the result.
633
634> **NOTE**<br>
635> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getLastLocation](js-apis-geoLocationManager.md#geolocationmanagergetlastlocation).
636
637**Required permissions**: ohos.permission.LOCATION
638
639**System capability**: SystemCapability.Location.Location.Core
640
641**Return value**
642
643  | Type| Description|
644  | -------- | -------- |
645  | Promise&lt;[Location](#locationdeprecated)&gt; | Promise used to return the result.|
646
647
648**Example**
649
650  ```ts
651  import geolocation from '@ohos.geolocation';
652  geolocation.getLastLocation().then((result) => {
653      console.info('getLastLocation: result: ' + JSON.stringify(result));
654  });
655  ```
656
657
658## geolocation.isLocationEnabled<sup>(deprecated)</sup>
659
660isLocationEnabled(callback: AsyncCallback&lt;boolean&gt;): void
661
662Checks whether the location service is enabled. This API uses an asynchronous callback to return the result.
663
664> **NOTE**<br>
665> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isLocationEnabled](js-apis-geoLocationManager.md#geolocationmanagerislocationenabled).
666
667**Required permissions**: ohos.permission.LOCATION
668
669**System capability**: SystemCapability.Location.Location.Core
670
671**Parameters**
672
673  | Name| Type| Mandatory| Description|
674  | -------- | -------- | -------- | -------- |
675  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. The value **true** indicates that the location service is enabled, and the value **false** indicates the opposite.|
676
677**Example**
678
679  ```ts
680  import geolocation from '@ohos.geolocation';
681  geolocation.isLocationEnabled((err, data) => {
682      if (err) {
683          console.info('isLocationEnabled: err=' + JSON.stringify(err));
684      }
685      if (data) {
686          console.info('isLocationEnabled: data=' + JSON.stringify(data));
687      }
688  });
689  ```
690
691
692## geolocation.isLocationEnabled<sup>(deprecated)</sup>
693
694isLocationEnabled(): Promise&lt;boolean&gt;
695
696Checks whether the location service is enabled. This API uses a promise to return the result.
697
698> **NOTE**<br>
699> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isLocationEnabled](js-apis-geoLocationManager.md#geolocationmanagerislocationenabled).
700
701**Required permissions**: ohos.permission.LOCATION
702
703**System capability**: SystemCapability.Location.Location.Core
704
705**Return value**
706
707  | Type| Description|
708  | -------- | -------- |
709  | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** indicates that the location service is enabled, and the value **false** indicates the opposite.|
710
711**Example**
712
713  ```ts
714  import geolocation from '@ohos.geolocation';
715  geolocation.isLocationEnabled().then((result) => {
716      console.info('promise, isLocationEnabled: ' + JSON.stringify(result));
717  });
718  ```
719
720
721## geolocation.requestEnableLocation<sup>(deprecated)</sup>
722
723requestEnableLocation(callback: AsyncCallback&lt;boolean&gt;): void
724
725Sends a request for enabling the location service. This API uses an asynchronous callback to return the result.
726
727> **NOTE**<br>
728> 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.
729
730**Required permissions**: ohos.permission.LOCATION
731
732**System capability**: SystemCapability.Location.Location.Core
733
734**Parameters**
735
736  | Name| Type| Mandatory| Description|
737  | -------- | -------- | -------- | -------- |
738  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. The value **true** indicates that the location service is enabled, and the value **false** indicates the opposite.|
739
740**Example**
741
742  ```ts
743  import geolocation from '@ohos.geolocation';
744  geolocation.requestEnableLocation((err, data) => {
745      if (err) {
746          console.info('requestEnableLocation: err=' + JSON.stringify(err));
747      }
748      if (data) {
749          console.info('requestEnableLocation: data=' + JSON.stringify(data));
750      }
751  });
752  ```
753
754
755## geolocation.requestEnableLocation<sup>(deprecated)</sup>
756
757requestEnableLocation(): Promise&lt;boolean&gt;
758
759Sends a request for enabling the location service. This API uses a promise to return the result.
760
761> **NOTE**<br>
762> 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.
763
764**Required permissions**: ohos.permission.LOCATION
765
766**System capability**: SystemCapability.Location.Location.Core
767
768**Return value**
769
770  | Type| Description|
771  | -------- | -------- |
772  | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** indicates that the location service is enabled, and the value **false** indicates the opposite.|
773
774**Example**
775
776  ```ts
777  import geolocation from '@ohos.geolocation';
778  geolocation.requestEnableLocation().then((result) => {
779      console.info('promise, requestEnableLocation: ' + JSON.stringify(result));
780  });
781  ```
782
783
784## geolocation.isGeoServiceAvailable<sup>(deprecated)</sup>
785
786isGeoServiceAvailable(callback: AsyncCallback&lt;boolean&gt;): void
787
788Checks whether the (reverse) geocoding service is available. This API uses an asynchronous callback to return the result.
789
790> **NOTE**<br>
791> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isGeocoderAvailable](js-apis-geoLocationManager.md#geolocationmanagerisgeocoderavailable).
792
793**Required permissions**: ohos.permission.LOCATION
794
795**System capability**: SystemCapability.Location.Location.Geocoder
796
797**Parameters**
798
799  | Name| Type| Mandatory| Description|
800  | -------- | -------- | -------- | -------- |
801  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. The value **true** indicates that the (reverse) geocoding service is available, and the value **false** indicates the opposite.|
802
803**Example**
804
805  ```ts
806  import geolocation from '@ohos.geolocation';
807  geolocation.isGeoServiceAvailable((err, data) => {
808      if (err) {
809          console.info('isGeoServiceAvailable: err=' + JSON.stringify(err));
810      }
811      if (data) {
812          console.info('isGeoServiceAvailable: data=' + JSON.stringify(data));
813      }
814  });
815  ```
816
817
818## geolocation.isGeoServiceAvailable<sup>(deprecated)</sup>
819
820isGeoServiceAvailable(): Promise&lt;boolean&gt;
821
822Checks whether the (reverse) geocoding service is available. This API uses a promise to return the result.
823
824> **NOTE**<br>
825> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isGeocoderAvailable](js-apis-geoLocationManager.md#geolocationmanagerisgeocoderavailable).
826
827**Required permissions**: ohos.permission.LOCATION
828
829**System capability**: SystemCapability.Location.Location.Geocoder
830
831**Return value**
832
833  | Type| Description|
834  | -------- | -------- |
835  | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** indicates that the (reverse) geocoding service is available, and the value **false** indicates the opposite.|
836
837**Example**
838
839  ```ts
840  import geolocation from '@ohos.geolocation';
841  geolocation.isGeoServiceAvailable().then((result) => {
842      console.info('promise, isGeoServiceAvailable: ' + JSON.stringify(result));
843  });
844  ```
845
846
847## geolocation.getAddressesFromLocation<sup>(deprecated)</sup>
848
849getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
850
851Converts coordinates into geographic descriptions through reverse geocoding. This API uses an asynchronous callback to return the result.
852
853> **NOTE**<br>
854> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocation](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocation).
855
856**Required permissions**: ohos.permission.LOCATION
857
858**System capability**: SystemCapability.Location.Location.Geocoder
859
860**Parameters**
861
862  | Name| Type| Mandatory| Description|
863  | -------- | -------- | -------- | -------- |
864  | request | [ReverseGeoCodeRequest](#reversegeocoderequestdeprecated) | Yes| Reverse geocoding request.|
865  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Yes| Callback used to return the result.|
866
867**Example**
868
869  ```ts
870  import geolocation from '@ohos.geolocation';
871  let reverseGeocodeRequest:geolocation.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
872  geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => {
873      if (err) {
874          console.info('getAddressesFromLocation: err=' + JSON.stringify(err));
875      }
876      if (data) {
877          console.info('getAddressesFromLocation: data=' + JSON.stringify(data));
878      }
879  });
880  ```
881
882
883## geolocation.getAddressesFromLocation<sup>(deprecated)</sup>
884
885getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;
886
887Converts coordinates into geographic descriptions through reverse geocoding. This API uses a promise to return the result.
888
889> **NOTE**<br>
890> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocation](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocation-1).
891
892**Required permissions**: ohos.permission.LOCATION
893
894**System capability**: SystemCapability.Location.Location.Geocoder
895
896**Parameters**
897
898  | Name| Type| Mandatory| Description|
899  | -------- | -------- | -------- | -------- |
900  | request | [ReverseGeoCodeRequest](#reversegeocoderequestdeprecated) | Yes| Reverse geocoding request.|
901
902**Return value**
903
904  | Type| Description|
905  | -------- | -------- |
906  | Promise&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Promise used to return the result.|
907
908**Example**
909
910  ```ts
911  import geolocation from '@ohos.geolocation';
912  let reverseGeocodeRequest:geolocation.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1};
913  geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => {
914      console.info('getAddressesFromLocation: ' + JSON.stringify(data));
915  });
916  ```
917
918
919## geolocation.getAddressesFromLocationName<sup>(deprecated)</sup>
920
921getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback&lt;Array&lt;GeoAddress&gt;&gt;): void
922
923Converts geographic descriptions into coordinates through geocoding. This API uses an asynchronous callback to return the result.
924
925> **NOTE**<br>
926> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocationName](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocationname).
927
928**Required permissions**: ohos.permission.LOCATION
929
930**System capability**: SystemCapability.Location.Location.Geocoder
931
932**Parameters**
933
934  | Name| Type| Mandatory| Description|
935  | -------- | -------- | -------- | -------- |
936  | request | [GeoCodeRequest](#geocoderequestdeprecated) | Yes| Geocoding request.|
937  | callback | AsyncCallback&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Yes| Callback used to return the result.|
938
939**Example**
940
941  ```ts
942  import geolocation from '@ohos.geolocation';
943  let geocodeRequest:geolocation.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
944  geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => {
945      if (err) {
946          console.info('getAddressesFromLocationName: err=' + JSON.stringify(err));
947      }
948      if (data) {
949          console.info('getAddressesFromLocationName: data=' + JSON.stringify(data));
950      }
951  });
952  ```
953
954
955## geolocation.getAddressesFromLocationName<sup>(deprecated)</sup>
956
957getAddressesFromLocationName(request: GeoCodeRequest): Promise&lt;Array&lt;GeoAddress&gt;&gt;
958
959Converts geographic descriptions into coordinates through geocoding. This API uses a promise to return the result.
960
961> **NOTE**<br>
962> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocationName](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocationname-1).
963
964**Required permissions**: ohos.permission.LOCATION
965
966**System capability**: SystemCapability.Location.Location.Geocoder
967
968**Parameters**
969
970  | Name| Type| Mandatory| Description|
971  | -------- | -------- | -------- | -------- |
972  | request | [GeoCodeRequest](#geocoderequestdeprecated) | Yes| Geocoding request.|
973
974**Return value**
975
976  | Type| Description|
977  | -------- | -------- |
978  | Promise&lt;Array&lt;[GeoAddress](#geoaddressdeprecated)&gt;&gt; | Promise used to return the result.|
979
980**Example**
981
982  ```ts
983  import geolocation from '@ohos.geolocation';
984  let geocodeRequest:geolocation.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1};
985  geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => {
986      console.info('getAddressesFromLocationName: ' + JSON.stringify(result));
987  });
988  ```
989
990
991## geolocation.getCachedGnssLocationsSize<sup>(deprecated)</sup>
992
993getCachedGnssLocationsSize(callback: AsyncCallback&lt;number&gt;): void
994
995Obtains the number of cached GNSS locations. This API uses an asynchronous callback to return the result.
996
997> **NOTE**<br>
998> This API is supported since API version 8.
999> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCachedGnssLocationsSize](js-apis-geoLocationManager.md#geolocationmanagergetcachedgnsslocationssize).
1000
1001**Required permissions**: ohos.permission.LOCATION
1002
1003**System capability**: SystemCapability.Location.Location.Gnss
1004
1005**Parameters**
1006
1007  | Name| Type| Mandatory| Description|
1008  | -------- | -------- | -------- | -------- |
1009  | callback | AsyncCallback&lt;number&gt; | Yes| Callback used to return the result.|
1010
1011**Example**
1012
1013  ```ts
1014  import geolocation from '@ohos.geolocation';
1015  geolocation.getCachedGnssLocationsSize((err, size) => {
1016      if (err) {
1017          console.info('getCachedGnssLocationsSize: err=' + JSON.stringify(err));
1018      }
1019      if (size) {
1020          console.info('getCachedGnssLocationsSize: size=' + JSON.stringify(size));
1021      }
1022  });
1023  ```
1024
1025
1026## geolocation.getCachedGnssLocationsSize<sup>(deprecated)</sup>
1027
1028getCachedGnssLocationsSize(): Promise&lt;number&gt;;
1029
1030Obtains the number of cached GNSS locations. This API uses a promise to return the result.
1031
1032> **NOTE**<br>
1033> This API is supported since API version 8.
1034> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCachedGnssLocationsSize](js-apis-geoLocationManager.md#geolocationmanagergetcachedgnsslocationssize-1).
1035
1036**Required permissions**: ohos.permission.LOCATION
1037
1038**System capability**: SystemCapability.Location.Location.Gnss
1039
1040**Return value**
1041
1042  | Type| Description|
1043  | -------- | -------- |
1044  | Promise&lt;number&gt; | Promise used to return the result.|
1045
1046**Example**
1047
1048  ```ts
1049  import geolocation from '@ohos.geolocation';
1050  geolocation.getCachedGnssLocationsSize().then((result) => {
1051      console.info('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result));
1052  });
1053  ```
1054
1055
1056## geolocation.flushCachedGnssLocations<sup>(deprecated)</sup>
1057
1058flushCachedGnssLocations(callback: AsyncCallback&lt;boolean&gt;): void
1059
1060Obtains all cached GNSS locations and clears the GNSS cache queue. This API uses an asynchronous callback to return the result.
1061
1062> **NOTE**<br>
1063> This API is supported since API version 8.
1064> This API is deprecated since API version 9. You are advised to use [geoLocationManager.flushCachedGnssLocations](js-apis-geoLocationManager.md#geolocationmanagerflushcachedgnsslocations).
1065
1066**Required permissions**: ohos.permission.LOCATION
1067
1068**System capability**: SystemCapability.Location.Location.Gnss
1069
1070**Parameters**
1071
1072  | Name| Type| Mandatory| Description|
1073  | -------- | -------- | -------- | -------- |
1074  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.|
1075
1076**Example**
1077
1078  ```ts
1079  import geolocation from '@ohos.geolocation';
1080  geolocation.flushCachedGnssLocations((err, result) => {
1081      if (err) {
1082          console.info('flushCachedGnssLocations: err=' + JSON.stringify(err));
1083      }
1084      if (result) {
1085          console.info('flushCachedGnssLocations: result=' + JSON.stringify(result));
1086      }
1087  });
1088  ```
1089
1090
1091## geolocation.flushCachedGnssLocations<sup>(deprecated)</sup>
1092
1093flushCachedGnssLocations(): Promise&lt;boolean&gt;
1094
1095Obtains all cached GNSS locations and clears the GNSS cache queue. This API uses a promise to return the result.
1096
1097> **NOTE**<br>
1098> This API is supported since API version 8.
1099> This API is deprecated since API version 9. You are advised to use [geoLocationManager.flushCachedGnssLocations](js-apis-geoLocationManager.md#geolocationmanagerflushcachedgnsslocations-1).
1100
1101**Required permissions**: ohos.permission.LOCATION
1102
1103**System capability**: SystemCapability.Location.Location.Gnss
1104
1105**Return value**
1106
1107  | Type| Description|
1108  | -------- | -------- |
1109  | Promise&lt;boolean&gt;| Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.|
1110
1111**Example**
1112
1113  ```ts
1114  import geolocation from '@ohos.geolocation';
1115  geolocation.flushCachedGnssLocations().then((result) => {
1116      console.info('promise, flushCachedGnssLocations: ' + JSON.stringify(result));
1117  });
1118  ```
1119
1120
1121## geolocation.sendCommand<sup>(deprecated)</sup>
1122
1123sendCommand(command: LocationCommand, callback: AsyncCallback&lt;boolean&gt;): void
1124
1125Sends an extended command to the location subsystem. This API uses an asynchronous callback to return the result.
1126
1127> **NOTE**<br>
1128> This API is supported since API version 8.
1129> This API is deprecated since API version 9. You are advised to use [geoLocationManager.sendCommand](js-apis-geoLocationManager.md#geolocationmanagersendcommand).
1130
1131**Required permissions**: ohos.permission.LOCATION
1132
1133**System capability**: SystemCapability.Location.Location.Core
1134
1135**Parameters**
1136
1137  | Name| Type| Mandatory| Description|
1138  | -------- | -------- | -------- | -------- |
1139  | command |  [LocationCommand](#locationcommanddeprecated) | Yes| Extended command (string) to be sent.|
1140  | callback | AsyncCallback&lt;boolean&gt; | Yes| Callback used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.|
1141
1142**Example**
1143
1144  ```ts
1145  import geolocation from '@ohos.geolocation';
1146  let requestInfo:geolocation.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
1147  geolocation.sendCommand(requestInfo, (err, result) => {
1148      if (err) {
1149          console.info('sendCommand: err=' + JSON.stringify(err));
1150      }
1151      if (result) {
1152          console.info('sendCommand: result=' + JSON.stringify(result));
1153      }
1154  });
1155  ```
1156
1157
1158## geolocation.sendCommand<sup>(deprecated)</sup>
1159
1160sendCommand(command: LocationCommand): Promise&lt;boolean&gt;
1161
1162Sends an extended command to the location subsystem. This API uses a promise to return the result.
1163
1164> **NOTE**<br>
1165> This API is supported since API version 8.
1166> This API is deprecated since API version 9. You are advised to use [geoLocationManager.sendCommand](js-apis-geoLocationManager.md#geolocationmanagersendcommand).
1167
1168**Required permissions**: ohos.permission.LOCATION
1169
1170**System capability**: SystemCapability.Location.Location.Core
1171
1172**Parameters**
1173
1174  | Name| Type| Mandatory| Description|
1175  | -------- | -------- | -------- | -------- |
1176  | command | [LocationCommand](#locationcommanddeprecated) | Yes| Extended command (string) to be sent.|
1177
1178**Return value**
1179
1180  | Type| Description|
1181  | -------- | -------- |
1182  | Promise&lt;boolean&gt; | Promise used to return the result. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.|
1183
1184**Example**
1185
1186  ```ts
1187  import geolocation from '@ohos.geolocation';
1188  let requestInfo:geolocation.LocationCommand = {'scenario': 0x301, 'command': "command_1"};
1189  geolocation.sendCommand(requestInfo).then((result) => {
1190      console.info('promise, sendCommand: ' + JSON.stringify(result));
1191  });
1192  ```
1193
1194
1195## ReverseGeoCodeRequest<sup>(deprecated)</sup>
1196
1197Defines a reverse geocoding request.
1198
1199> **NOTE**<br>
1200> This API is deprecated since API version 9. You are advised to use [geoLocationManager.ReverseGeoCodeRequest](js-apis-geoLocationManager.md#reversegeocoderequest).
1201
1202**Required permissions**: ohos.permission.LOCATION
1203
1204**System capability**: SystemCapability.Location.Location.Geocoder
1205
1206| Name| Type| Read Only| Optional| Description|
1207| -------- | -------- | -------- | -------- | -------- |
1208| locale | string | No| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
1209| latitude | number | No| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.|
1210| longitude | number | No| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.|
1211| maxItems | number | No| 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.|
1212
1213
1214## GeoCodeRequest<sup>(deprecated)</sup>
1215
1216Defines a reverse geocoding request.
1217
1218> **NOTE**<br>
1219> This API is deprecated since API version 9. You are advised to use [geoLocationManager.GeoCodeRequest](js-apis-geoLocationManager.md#geocoderequest).
1220
1221**Required permissions**: ohos.permission.LOCATION
1222
1223**System capability**: SystemCapability.Location.Location.Geocoder
1224
1225| Name| Type| Read Only| Optional| Description|
1226| -------- | -------- | -------- | -------- | -------- |
1227| locale | string | No| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
1228| description | string | No| No| Location description, for example, **No. xx, xx Road, Pudong New District, Shanghai**.|
1229| maxItems | number | No| 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.|
1230| minLatitude | number | No| 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**.|
1231| minLongitude | number | No| Yes| Minimum longitude. The value ranges from **-180** to **180**.|
1232| maxLatitude | number | No| Yes| Maximum latitude. The value ranges from **-90** to **90**.|
1233| maxLongitude | number | No| Yes| Maximum longitude. The value ranges from **-180** to **180**.|
1234
1235
1236## GeoAddress<sup>(deprecated)</sup>
1237
1238Geocoding address information.
1239
1240> **NOTE**<br>
1241> This API is deprecated since API version 9. You are advised to use [geoLocationManager.GeoAddress](js-apis-geoLocationManager.md#geoaddress).
1242
1243**Required permissions**: ohos.permission.LOCATION
1244
1245**System capability**: SystemCapability.Location.Location.Geocoder
1246
1247| Name| Type| Read Only| Optional| Description|
1248| -------- | -------- | -------- | -------- | -------- |
1249| latitude<sup>7+</sup> | number | No| Yes| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.|
1250| longitude<sup>7+</sup> | number | No| Yes| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.|
1251| locale<sup>7+</sup> | string | No| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.|
1252| placeName<sup>7+</sup> | string | No| Yes| Landmark of the location.|
1253| countryCode<sup>7+</sup> | string | No| Yes| Country code.|
1254| countryName<sup>7+</sup> | string | No| Yes| Country name.|
1255| administrativeArea<sup>7+</sup> | string | No| Yes| Administrative region name.|
1256| subAdministrativeArea<sup>7+</sup> | string | No| Yes| Sub-administrative region name.|
1257| locality<sup>7+</sup> | string | No| Yes| Locality information.|
1258| subLocality<sup>7+</sup> | string | No| Yes| Sub-locality information.|
1259| roadName<sup>7+</sup> | string | No| Yes| Road name.|
1260| subRoadName<sup>7+</sup> | string | No| Yes| Auxiliary road information.|
1261| premises<sup>7+</sup> | string | No| Yes| House information.|
1262| postalCode<sup>7+</sup> | string | No| Yes| Postal code.|
1263| phoneNumber<sup>7+</sup> | string | No| Yes| Phone number.|
1264| addressUrl<sup>7+</sup> | string | No| Yes| Website URL.|
1265| descriptions<sup>7+</sup> | Array&lt;string&gt; | No| Yes| Additional descriptions.|
1266| descriptionsSize<sup>7+</sup> | number | No| Yes| Total number of additional descriptions. The value must be greater than or equal to **0**. A value smaller than **10** is recommended.|
1267
1268
1269## LocationRequest<sup>(deprecated)</sup>
1270
1271Defines a location request.
1272
1273> **NOTE**<br>
1274> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationRequest](js-apis-geoLocationManager.md#locationrequest).
1275
1276**Required permissions**: ohos.permission.LOCATION
1277
1278**System capability**: SystemCapability.Location.Location.Core
1279
1280| Name| Type| Read Only| Optional| Description|
1281| -------- | -------- | -------- | -------- | -------- |
1282| priority | [LocationRequestPriority](#locationrequestprioritydeprecated) | No| Yes| Priority of the location request. For details about the value range, see [LocationRequestPriority](#locationrequestprioritydeprecated).|
1283| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated) | No| Yes| Scenario of the location request. For details about the value range, see [LocationRequestScenario](#locationrequestscenariodeprecated).|
1284| timeInterval | number | No| Yes| Time interval at which location information is reported, in seconds. The value must be greater than **0**.|
1285| distanceInterval | number | No| Yes| Distance interval at which location information is reported. The value must be greater than **0**, in meters.|
1286| maxAccuracy | number | No| Yes| Location accuracy, in meters.<br>This parameter is valid only when the precise location function is enabled (both the **ohos.permission.APPROXIMATELY\_LOCATION** and **ohos.permission.LOCATION** permissions are granted), and is invalid when the approximate location function is enabled (only the **ohos.permission.APPROXIMATELY\_LOCATION** permission is enabled).<br>The specified value must be greater than or equal to **0**. The default value is **0**.<br>If **scenario** is set to **NAVIGATION**, **TRAJECTORY\_TRACKING**, or **CAR\_HAILING** or **priority** is set to **ACCURACY**, you are advised to set **maxAccuracy** to a value greater than **10**.<br>If scenario is set to **DAILY\_LIFE_SERVICE** or **NO\_POWER** or **priority** is set to **LOW\_POWER** or **FIRST\_FIX**, you are advised to set **maxAccuracy** to a value greater than **100**.|
1287
1288
1289## CurrentLocationRequest<sup>(deprecated)</sup>
1290
1291Defines a location request.
1292
1293> **NOTE**<br>
1294> This API is deprecated since API version 9. You are advised to use [geoLocationManager.CurrentLocationRequest](js-apis-geoLocationManager.md#currentlocationrequest).
1295
1296**Required permissions**: ohos.permission.LOCATION
1297
1298**System capability**: SystemCapability.Location.Location.Core
1299
1300| Name| Type| Read Only| Optional| Description|
1301| -------- | -------- | -------- | -------- | -------- |
1302| priority | [LocationRequestPriority](#locationrequestprioritydeprecated) | No| Yes| Priority of the location request. For details about the value range, see [LocationRequestPriority](#locationrequestprioritydeprecated).|
1303| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated) | No| Yes| Scenario of the location request. For details about the value range, see [LocationRequestScenario](#locationrequestscenariodeprecated).|
1304| maxAccuracy | number | No| Yes| Location accuracy, in meters.<br>This parameter is valid only when the precise location function is enabled (both the **ohos.permission.APPROXIMATELY\_LOCATION** and **ohos.permission.LOCATION** permissions are granted), and is invalid when the approximate location function is enabled (only the **ohos.permission.APPROXIMATELY\_LOCATION** permission is enabled).<br>The specified value must be greater than or equal to **0**. The default value is **0**.<br>If **scenario** is set to **NAVIGATION**, **TRAJECTORY\_TRACKING**, or **CAR\_HAILING** or **priority** is set to **ACCURACY**, you are advised to set **maxAccuracy** to a value greater than **10**.<br>If scenario is set to **DAILY\_LIFE_SERVICE** or **NO\_POWER** or **priority** is set to **LOW\_POWER** or **FIRST\_FIX**, you are advised to set **maxAccuracy** to a value greater than **100**.|
1305| timeoutMs | number | No| Yes| Timeout duration, in milliseconds. The minimum value is **1000**. The value must be greater than or equal to **1000**.|
1306
1307
1308## SatelliteStatusInfo<sup>(deprecated)</sup>
1309
1310Defines the satellite status information.
1311
1312> **NOTE**<br>
1313> This API is supported since API version 8.
1314> This API is deprecated since API version 9. You are advised to use [geoLocationManager.SatelliteStatusInfo](js-apis-geoLocationManager.md#satellitestatusinfo).
1315
1316**Required permissions**: ohos.permission.LOCATION
1317
1318**System capability**: SystemCapability.Location.Location.Gnss
1319
1320| Name| Type| Read Only| Optional| Description|
1321| -------- | -------- | -------- | -------- | -------- |
1322| satellitesNumber | number | No| No| Number of satellites. The value must be greater than or equal to **0**.|
1323| satelliteIds | Array&lt;number&gt; | No| No| Array of satellite IDs. The value must be greater than or equal to **0**.|
1324| carrierToNoiseDensitys | Array&lt;number&gt; | No| No| Carrier-to-noise density ratio, that is, **cn0**. The value must be greater than **0**.|
1325| altitudes | Array&lt;number&gt; | No| No| Satellite altitude angle information. The value ranges from **-90** to **90**, in degrees.|
1326| azimuths | Array&lt;number&gt; | No| No| Azimuth information. The value ranges from **0** to **360**, in degrees.|
1327| carrierFrequencies | Array&lt;number&gt; | No| No| Carrier frequency. The value must be greater than or equal to **0**, in Hz.|
1328
1329
1330## CachedGnssLocationsRequest<sup>(deprecated)</sup>
1331
1332Represents a request for reporting cached GNSS locations.
1333
1334> **NOTE**<br>
1335> This API is supported since API version 8.
1336> This API is deprecated since API version 9. You are advised to use [geoLocationManager.CachedGnssLocationsRequest](js-apis-geoLocationManager.md#cachedgnsslocationsrequest).
1337
1338**Required permissions**: ohos.permission.LOCATION
1339
1340**System capability**: SystemCapability.Location.Location.Gnss
1341
1342| Name| Type| Read Only| Optional| Description|
1343| -------- | -------- | -------- | -------- | -------- |
1344| reportingPeriodSec | number | No| No| Interval for reporting the cached GNSS locations, in milliseconds. The value must be greater than **0**.|
1345| wakeUpCacheQueueFull | boolean | No| No| **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.|
1346
1347
1348## Geofence<sup>(deprecated)</sup>
1349
1350Defines a GNSS geofence. Currently, only circular geofences are supported.
1351
1352> **NOTE**<br>
1353> This API is supported since API version 8.
1354> This API is deprecated since API version 9. You are advised to use [geoLocationManager.Geofence](js-apis-geoLocationManager.md#geofence).
1355
1356**Required permissions**: ohos.permission.LOCATION
1357
1358**System capability**: SystemCapability.Location.Location.Geofence
1359
1360| Name| Type| Read Only| Optional| Description|
1361| -------- | -------- | -------- | -------- | -------- |
1362| latitude | number | No| No|Latitude information. The value ranges from **-90** to **90**.|
1363| longitude | number | No| No| Longitude information. The value ranges from **-180** to **180**.|
1364| radius | number | No| No| Radius of a circular geofence. The value must be greater than **0**, in meters.|
1365| expiration | number | No| No| Expiration period of a geofence, in milliseconds. The value must be greater than **0**.|
1366
1367
1368## GeofenceRequest<sup>(deprecated)</sup>
1369
1370Defines a geofence request.
1371
1372> **NOTE**<br>
1373> This API is supported since API version 8.
1374> This API is deprecated since API version 9. You are advised to use [geoLocationManager.GeofenceRequest](js-apis-geoLocationManager.md#geofencerequest).
1375
1376**Required permissions**: ohos.permission.LOCATION
1377
1378**System capability**: SystemCapability.Location.Location.Geofence
1379
1380| Name| Type| Read Only| Optional| Description|
1381| -------- | -------- | -------- | -------- | -------- |
1382| priority | [LocationRequestPriority](#locationrequestprioritydeprecated) | No| No| Priority of the location information.|
1383| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated) | No| No| Location scenario.|
1384| geofence | [Geofence](#geofencedeprecated)| No| No| Geofence information.|
1385
1386
1387## LocationCommand<sup>(deprecated)</sup>
1388
1389Defines a location command.
1390
1391> **NOTE**<br>
1392> This API is supported since API version 8.
1393> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationCommand](js-apis-geoLocationManager.md#locationcommand).
1394
1395**Required permissions**: ohos.permission.LOCATION
1396
1397**System capability**: SystemCapability.Location.Location.Core
1398
1399| Name| Type| Read Only| Optional| Description|
1400| -------- | -------- | -------- | -------- | -------- |
1401| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated)  | No| No| Location scenario.|
1402| command | string | No| No| Extended command, in the string format.|
1403
1404
1405## Location<sup>(deprecated)</sup>
1406
1407Defines location information.
1408
1409> **NOTE**<br>
1410> This API is deprecated since API version 9. You are advised to use [geoLocationManager.Location](js-apis-geoLocationManager.md#location).
1411
1412**Required permissions**: ohos.permission.LOCATION
1413
1414**System capability**: SystemCapability.Location.Location.Core
1415
1416| Name| Type| Read Only| Optional| Description|
1417| -------- | -------- | -------- | -------- | -------- |
1418| latitude<sup>7+</sup> | number | No| No| Latitude information. A positive value indicates north latitude, and a negative value indicates south latitude. The value ranges from **-90** to **90**.|
1419| longitude<sup>7+</sup> | number | No| No| Longitude information. A positive value indicates east longitude , and a negative value indicates west longitude . The value ranges from **-180** to **180**.|
1420| altitude<sup>7+</sup> | number | No| No| Location altitude, in meters.|
1421| accuracy<sup>7+</sup> | number | No| No| Location accuracy, in meters.|
1422| speed<sup>7+</sup> | number | No| No| Speed, in m/s.|
1423| timeStamp<sup>7+</sup> | number | No| No| Location timestamp in the UTC format.|
1424| direction<sup>7+</sup> | number | No| No| Direction information. The value ranges from **0** to **360**, in degrees.|
1425| timeSinceBoot<sup>7+</sup> | number | No| No| Location timestamp since boot.|
1426| additions<sup>7+</sup> | Array&lt;string&gt; | No| Yes| Additional description.|
1427| additionSize<sup>7+</sup> | number | No| Yes| Number of additional descriptions. The value must be greater than or equal to **0**.|
1428
1429
1430## LocationPrivacyType<sup>(deprecated)</sup>
1431
1432Defines the privacy statement type.
1433
1434> **NOTE**<br>
1435> This API is supported since API version 8.
1436> This API is deprecated since API version 9. You are advised to use **geoLocationManager.LocationPrivacyType**, which is available only for system applications.
1437
1438**Required permissions**: ohos.permission.LOCATION
1439
1440**System capability**: SystemCapability.Location.Location.Core
1441
1442| Name| Value| Description|
1443| -------- | -------- | -------- |
1444| OTHERS | 0 | Other scenarios. Reserved field.|
1445| STARTUP | 1 | Privacy statement displayed in the startup wizard.  |
1446| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.|
1447
1448
1449## LocationRequestPriority<sup>(deprecated)</sup>
1450
1451Sets the priority of a location request.
1452
1453> **NOTE**<br>
1454> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationRequestPriority](js-apis-geoLocationManager.md#locationrequestpriority).
1455
1456**Required permissions**: ohos.permission.LOCATION
1457
1458**System capability**: SystemCapability.Location.Location.Core
1459
1460| Name| Value| Description|
1461| -------- | -------- | -------- |
1462| UNSET | 0x200 | Priority unspecified.<br>If this option is used, [LocationRequestPriority](#locationrequestprioritydeprecated) is invalid.|
1463| 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.|
1464| 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.|
1465| 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.|
1466
1467
1468## LocationRequestScenario<sup>(deprecated)</sup>
1469
1470  Defines the location scenario in a location request.
1471
1472> **NOTE**<br>
1473> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationRequestScenario](js-apis-geoLocationManager.md#locationrequestscenario).
1474
1475**Required permissions**: ohos.permission.LOCATION
1476
1477**System capability**: SystemCapability.Location.Location.Core
1478
1479| Name| Value| Description|
1480| -------- | -------- | -------- |
1481| UNSET | 0x300 | Scenario unspecified.<br>If this option is used, [LocationRequestScenario](#locationrequestscenariodeprecated) is invalid.|
1482| 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.|
1483| 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.|
1484| 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.|
1485| 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.|
1486| 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.|
1487
1488
1489## GeoLocationErrorCode<sup>(deprecated)</sup>
1490
1491Enumerates error codes of the location service.
1492
1493> **NOTE**<br>
1494> This API is deprecated since API version 9. You are advised to use [geoLocationManager](errorcode-geoLocationManager.md).
1495
1496**Required permissions**: ohos.permission.LOCATION
1497
1498**System capability**: SystemCapability.Location.Location.Core
1499
1500| Name| Value| Description|
1501| -------- | -------- | -------- |
1502| INPUT_PARAMS_ERROR<sup>7+</sup> | 101 | Incorrect input parameters.|
1503| REVERSE_GEOCODE_ERROR<sup>7+</sup> | 102 | Failed to call the reverse geocoding API.|
1504| GEOCODE_ERROR<sup>7+</sup> | 103 | Failed to call the geocoding API.|
1505| LOCATOR_ERROR<sup>7+</sup> | 104 | Failed to obtain the location.|
1506| LOCATION_SWITCH_ERROR<sup>7+</sup> | 105 | Failed to change the location service switch.|
1507| LAST_KNOWN_LOCATION_ERROR<sup>7+</sup> | 106 | Failed to obtain the previous location.|
1508| LOCATION_REQUEST_TIMEOUT_ERROR<sup>7+</sup> | 107 | Failed to obtain the location within the specified time.|
1509