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