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