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) instead. 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 return the location change event.| 64 65 66 67**Example** 68 69 ```ts 70 import geolocation from '@ohos.geolocation'; 71 let requestInfo = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; 72 let locationChange = (location) => { 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 = {'priority': 0x203, 'scenario': 0x300, 'timeInterval': 0, 'distanceInterval': 0, 'maxAccuracy': 0}; 105 let locationChange = (location) => { 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 return the location service status change event.| 132 133 134**Example** 135 136 ```ts 137 import geolocation from '@ohos.geolocation'; 138 let locationServiceState = (state) => { 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) => { 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 return cached GNSS locations.| 199 200 201**Example** 202 203 ```ts 204 import geolocation from '@ohos.geolocation'; 205 let cachedLocationsCb = (locations) => { 206 console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); 207 } 208 let requestInfo = {'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) => { 240 console.log('cachedGnssLocationsReporting: locations: ' + JSON.stringify(locations)); 241 } 242 let requestInfo = {'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 return GNSS satellite status changes.| 268 269 270**Example** 271 272 ```ts 273 import geolocation from '@ohos.geolocation'; 274 let gnssStatusCb = (satelliteStatusInfo) => { 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) => { 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 return GNSS NMEA message changes.| 334 335 336**Example** 337 338 ```ts 339 import geolocation from '@ohos.geolocation'; 340 let nmeaCb = (str) => { 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) => { 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 return 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 = { 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 = {'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 return 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 = { 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 = {'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 return the current location.| 497 498**Example** 499 500 ```ts 501 import geolocation from '@ohos.geolocation'; 502 let requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0}; 503 let locationChange = (err, location) => { 504 if (err) { 505 console.log('locationChanger: err=' + JSON.stringify(err)); 506 } 507 if (location) { 508 console.log('locationChanger: location=' + JSON.stringify(location)); 509 } 510 }; 511 geolocation.getCurrentLocation(requestInfo, locationChange); 512 ``` 513 514 515## geolocation.getCurrentLocation<sup>(deprecated)</sup> 516 517getCurrentLocation(callback: AsyncCallback<Location>): void 518 519 520Obtains the current location. This API uses an asynchronous callback to return the result. 521 522> **NOTE**<br> 523> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCurrentLocation](js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation). 524 525**Required permissions**: ohos.permission.LOCATION 526 527**System capability**: SystemCapability.Location.Location.Core 528 529**Parameters** 530 531 | Name| Type| Mandatory| Description| 532 | -------- | -------- | -------- | -------- | 533 | callback | AsyncCallback<[Location](#locationdeprecated)> | Yes| Callback used to return the current location.| 534 535**Example** 536 537 ```ts 538 import geolocation from '@ohos.geolocation'; 539 let locationChange = (err, location) => { 540 if (err) { 541 console.log('locationChanger: err=' + JSON.stringify(err)); 542 } 543 if (location) { 544 console.log('locationChanger: location=' + JSON.stringify(location)); 545 } 546 }; 547 geolocation.getCurrentLocation(locationChange); 548 ``` 549 550 551## geolocation.getCurrentLocation<sup>(deprecated)</sup> 552 553getCurrentLocation(request?: CurrentLocationRequest): Promise<Location> 554 555Obtains the current location. This API uses a promise to return the result. 556 557> **NOTE**<br> 558> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCurrentLocation](js-apis-geoLocationManager.md#geolocationmanagergetcurrentlocation-2). 559 560**Required permissions**: ohos.permission.LOCATION 561 562**System capability**: SystemCapability.Location.Location.Core 563 564**Parameters** 565 566 | Name| Type| Mandatory| Description| 567 | -------- | -------- | -------- | -------- | 568 | request | [CurrentLocationRequest](#currentlocationrequestdeprecated) | No| Location request.| 569 570**Return value** 571 572 | Name| Type| Mandatory| Description| 573 | -------- | -------- | -------- | -------- | 574 | Promise<[Location](#locationdeprecated)> |[Location](#locationdeprecated)|NA| Promise used to return the current location.| 575 576 577**Example** 578 579 ```ts 580 import geolocation from '@ohos.geolocation'; 581 let requestInfo = {'priority': 0x203, 'scenario': 0x300,'maxAccuracy': 0}; 582 geolocation.getCurrentLocation(requestInfo).then((result) => { 583 console.log('current location: ' + JSON.stringify(result)); 584 }); 585 ``` 586 587 588## geolocation.getLastLocation<sup>(deprecated)</sup> 589 590getLastLocation(callback: AsyncCallback<Location>): void 591 592Obtains the previous location. This API uses an asynchronous callback to return the result. 593 594> **NOTE**<br> 595> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getLastLocation](js-apis-geoLocationManager.md#geolocationmanagergetlastlocation). 596 597**Required permissions**: ohos.permission.LOCATION 598 599**System capability**: SystemCapability.Location.Location.Core 600 601**Parameters** 602 603 | Name| Type| Mandatory| Description| 604 | -------- | -------- | -------- | -------- | 605 | callback | AsyncCallback<[Location](#locationdeprecated)> | Yes| Callback used to return the previous location.| 606 607 608**Example** 609 610 ```ts 611 import geolocation from '@ohos.geolocation'; 612 geolocation.getLastLocation((err, data) => { 613 if (err) { 614 console.log('getLastLocation: err=' + JSON.stringify(err)); 615 } 616 if (data) { 617 console.log('getLastLocation: data=' + JSON.stringify(data)); 618 } 619 }); 620 ``` 621 622 623## geolocation.getLastLocation<sup>(deprecated)</sup> 624 625getLastLocation(): Promise<Location> 626 627Obtains the previous location. This API uses a promise to return the result. 628 629> **NOTE**<br> 630> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getLastLocation](js-apis-geoLocationManager.md#geolocationmanagergetlastlocation). 631 632**Required permissions**: ohos.permission.LOCATION 633 634**System capability**: SystemCapability.Location.Location.Core 635 636**Return value** 637 638 | Name| Type| Mandatory| Description| 639 | -------- | -------- | -------- | -------- | 640 | Promise<[Location](#locationdeprecated)> | [Location](#locationdeprecated)|NA|Promise used to return the previous location.| 641 642 643**Example** 644 645 ```ts 646 import geolocation from '@ohos.geolocation'; 647 geolocation.getLastLocation().then((result) => { 648 console.log('getLastLocation: result: ' + JSON.stringify(result)); 649 }); 650 ``` 651 652 653## geolocation.isLocationEnabled<sup>(deprecated)</sup> 654 655isLocationEnabled(callback: AsyncCallback<boolean>): void 656 657Checks whether the location service is enabled. This API uses an asynchronous callback to return the result. 658 659> **NOTE**<br> 660> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isLocationEnabled](js-apis-geoLocationManager.md#geolocationmanagerislocationenabled). 661 662**Required permissions**: ohos.permission.LOCATION 663 664**System capability**: SystemCapability.Location.Location.Core 665 666**Parameters** 667 668 | Name| Type| Mandatory| Description| 669 | -------- | -------- | -------- | -------- | 670 | callback | AsyncCallback<boolean> | Yes| Callback used to return the location service status.| 671 672**Example** 673 674 ```ts 675 import geolocation from '@ohos.geolocation'; 676 geolocation.isLocationEnabled((err, data) => { 677 if (err) { 678 console.log('isLocationEnabled: err=' + JSON.stringify(err)); 679 } 680 if (data) { 681 console.log('isLocationEnabled: data=' + JSON.stringify(data)); 682 } 683 }); 684 ``` 685 686 687## geolocation.isLocationEnabled<sup>(deprecated)</sup> 688 689isLocationEnabled(): Promise<boolean> 690 691Checks whether the location service is enabled. This API uses a promise to return the result. 692 693> **NOTE**<br> 694> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isLocationEnabled](js-apis-geoLocationManager.md#geolocationmanagerislocationenabled). 695 696**Required permissions**: ohos.permission.LOCATION 697 698**System capability**: SystemCapability.Location.Location.Core 699 700**Return value** 701 702 | Name| Type| Mandatory| Description| 703 | -------- | -------- | -------- | -------- | 704 | Promise<boolean> | boolean|NA|Promise used to return the location service status.| 705 706**Example** 707 708 ```ts 709 import geolocation from '@ohos.geolocation'; 710 geolocation.isLocationEnabled().then((result) => { 711 console.log('promise, isLocationEnabled: ' + JSON.stringify(result)); 712 }); 713 ``` 714 715 716## geolocation.requestEnableLocation<sup>(deprecated)</sup> 717 718requestEnableLocation(callback: AsyncCallback<boolean>): void 719 720Requests to enable the location service. This API uses an asynchronous callback to return the result. 721 722> **NOTE**<br> 723> 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. 724 725**Required permissions**: ohos.permission.LOCATION 726 727**System capability**: SystemCapability.Location.Location.Core 728 729**Parameters** 730 731 | Name| Type| Mandatory| Description| 732 | -------- | -------- | -------- | -------- | 733 | callback | AsyncCallback<boolean> | Yes| Callback used to return the location service status.| 734 735**Example** 736 737 ```ts 738 import geolocation from '@ohos.geolocation'; 739 geolocation.requestEnableLocation((err, data) => { 740 if (err) { 741 console.log('requestEnableLocation: err=' + JSON.stringify(err)); 742 } 743 if (data) { 744 console.log('requestEnableLocation: data=' + JSON.stringify(data)); 745 } 746 }); 747 ``` 748 749 750## geolocation.requestEnableLocation<sup>(deprecated)</sup> 751 752requestEnableLocation(): Promise<boolean> 753 754Requests to enable the location service. This API uses a promise to return the result. 755 756> **NOTE**<br> 757> 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. 758 759**Required permissions**: ohos.permission.LOCATION 760 761**System capability**: SystemCapability.Location.Location.Core 762 763**Return value** 764 765 | Name| Type| Mandatory| Description| 766 | -------- | -------- | -------- | -------- | 767 | Promise<boolean> | boolean|NA|Promise used to return the location service status.| 768 769**Example** 770 771 ```ts 772 import geolocation from '@ohos.geolocation'; 773 geolocation.requestEnableLocation().then((result) => { 774 console.log('promise, requestEnableLocation: ' + JSON.stringify(result)); 775 }); 776 ``` 777 778 779## geolocation.isGeoServiceAvailable<sup>(deprecated)</sup> 780 781isGeoServiceAvailable(callback: AsyncCallback<boolean>): void 782 783Checks whether the (reverse) geocoding service is available. This API uses an asynchronous callback to return the result. 784 785> **NOTE**<br> 786> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isGeocoderAvailable](js-apis-geoLocationManager.md#geolocationmanagerisgeocoderavailable). 787 788**Required permissions**: ohos.permission.LOCATION 789 790**System capability**: SystemCapability.Location.Location.Geocoder 791 792**Parameters** 793 794 | Name| Type| Mandatory| Description| 795 | -------- | -------- | -------- | -------- | 796 | callback | AsyncCallback<boolean> | Yes| Callback used to return the (reverse) geocoding service status.| 797 798**Example** 799 800 ```ts 801 import geolocation from '@ohos.geolocation'; 802 geolocation.isGeoServiceAvailable((err, data) => { 803 if (err) { 804 console.log('isGeoServiceAvailable: err=' + JSON.stringify(err)); 805 } 806 if (data) { 807 console.log('isGeoServiceAvailable: data=' + JSON.stringify(data)); 808 } 809 }); 810 ``` 811 812 813## geolocation.isGeoServiceAvailable<sup>(deprecated)</sup> 814 815isGeoServiceAvailable(): Promise<boolean> 816 817Checks whether the (reverse) geocoding service is available. This API uses a promise to return the result. 818 819> **NOTE**<br> 820> This API is deprecated since API version 9. You are advised to use [geoLocationManager.isGeocoderAvailable](js-apis-geoLocationManager.md#geolocationmanagerisgeocoderavailable). 821 822**Required permissions**: ohos.permission.LOCATION 823 824**System capability**: SystemCapability.Location.Location.Geocoder 825 826**Return value** 827 828 | Name| Type| Mandatory| Description| 829 | -------- | -------- | -------- | -------- | 830 | Promise<boolean> |boolean|NA| Promise used to return the (reverse) geocoding service status.| 831 832**Example** 833 834 ```ts 835 import geolocation from '@ohos.geolocation'; 836 geolocation.isGeoServiceAvailable().then((result) => { 837 console.log('promise, isGeoServiceAvailable: ' + JSON.stringify(result)); 838 }); 839 ``` 840 841 842## geolocation.getAddressesFromLocation<sup>(deprecated)</sup> 843 844getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void 845 846Converts coordinates into geographic descriptions through reverse geocoding. This API uses an asynchronous callback to return the result. 847 848> **NOTE**<br> 849> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocation](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocation). 850 851**Required permissions**: ohos.permission.LOCATION 852 853**System capability**: SystemCapability.Location.Location.Geocoder 854 855**Parameters** 856 857 | Name| Type| Mandatory| Description| 858 | -------- | -------- | -------- | -------- | 859 | request | [ReverseGeoCodeRequest](#reversegeocoderequestdeprecated) | Yes| Reverse geocoding request.| 860 | callback | AsyncCallback<Array<[GeoAddress](#geoaddressdeprecated)>> | Yes| Callback used to return the reverse geocoding result.| 861 862**Example** 863 864 ```ts 865 import geolocation from '@ohos.geolocation'; 866 let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; 867 geolocation.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { 868 if (err) { 869 console.log('getAddressesFromLocation: err=' + JSON.stringify(err)); 870 } 871 if (data) { 872 console.log('getAddressesFromLocation: data=' + JSON.stringify(data)); 873 } 874 }); 875 ``` 876 877 878## geolocation.getAddressesFromLocation<sup>(deprecated)</sup> 879 880getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise<Array<GeoAddress>>; 881 882Converts coordinates into geographic descriptions through reverse geocoding. This API uses a promise to return the result. 883 884> **NOTE**<br> 885> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocation](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocation-1). 886 887**Required permissions**: ohos.permission.LOCATION 888 889**System capability**: SystemCapability.Location.Location.Geocoder 890 891**Parameters** 892 893 | Name| Type| Mandatory| Description| 894 | -------- | -------- | -------- | -------- | 895 | request | [ReverseGeoCodeRequest](#reversegeocoderequestdeprecated) | Yes| Reverse geocoding request.| 896 897**Return value** 898 899 | Name| Type| Mandatory| Description| 900 | -------- | -------- | -------- | -------- | 901 | Promise<Array<[GeoAddress](#geoaddressdeprecated)>> | Array<[GeoAddress](#geoaddressdeprecated)>|NA|Promise used to return the reverse geocoding result.| 902 903**Example** 904 905 ```ts 906 import geolocation from '@ohos.geolocation'; 907 let reverseGeocodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; 908 geolocation.getAddressesFromLocation(reverseGeocodeRequest).then((data) => { 909 console.log('getAddressesFromLocation: ' + JSON.stringify(data)); 910 }); 911 ``` 912 913 914## geolocation.getAddressesFromLocationName<sup>(deprecated)</sup> 915 916getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void 917 918Converts geographic descriptions into coordinates through geocoding. This API uses an asynchronous callback to return the result. 919 920> **NOTE**<br> 921> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocationName](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocationname). 922 923**Required permissions**: ohos.permission.LOCATION 924 925**System capability**: SystemCapability.Location.Location.Geocoder 926 927**Parameters** 928 929 | Name| Type| Mandatory| Description| 930 | -------- | -------- | -------- | -------- | 931 | request | [GeoCodeRequest](#geocoderequestdeprecated) | Yes| Geocoding request.| 932 | callback | AsyncCallback<Array<[GeoAddress](#geoaddressdeprecated)>> | Yes| Callback used to return the geocoding result.| 933 934**Example** 935 936 ```ts 937 import geolocation from '@ohos.geolocation'; 938 let geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; 939 geolocation.getAddressesFromLocationName(geocodeRequest, (err, data) => { 940 if (err) { 941 console.log('getAddressesFromLocationName: err=' + JSON.stringify(err)); 942 } 943 if (data) { 944 console.log('getAddressesFromLocationName: data=' + JSON.stringify(data)); 945 } 946 }); 947 ``` 948 949 950## geolocation.getAddressesFromLocationName<sup>(deprecated)</sup> 951 952getAddressesFromLocationName(request: GeoCodeRequest): Promise<Array<GeoAddress>> 953 954Converts geographic descriptions into coordinates through geocoding. This API uses a promise to return the result. 955 956> **NOTE**<br> 957> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getAddressesFromLocationName](js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocationname-1). 958 959**Required permissions**: ohos.permission.LOCATION 960 961**System capability**: SystemCapability.Location.Location.Geocoder 962 963**Parameters** 964 965 | Name| Type| Mandatory| Description| 966 | -------- | -------- | -------- | -------- | 967 | request | [GeoCodeRequest](#geocoderequestdeprecated) | Yes| Geocoding request.| 968 969**Return value** 970 971 | Name| Type| Mandatory| Description| 972 | -------- | -------- | -------- | -------- | 973 | Promise<Array<[GeoAddress](#geoaddressdeprecated)>> | Array<[GeoAddress](#geoaddressdeprecated)>|NA|Promise used to return the geocoding result.| 974 975**Example** 976 977 ```ts 978 import geolocation from '@ohos.geolocation'; 979 let geocodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; 980 geolocation.getAddressesFromLocationName(geocodeRequest).then((result) => { 981 console.log('getAddressesFromLocationName: ' + JSON.stringify(result)); 982 }); 983 ``` 984 985 986## geolocation.getCachedGnssLocationsSize<sup>(deprecated)</sup> 987 988getCachedGnssLocationsSize(callback: AsyncCallback<number>): void; 989 990Obtains the number of cached GNSS locations. 991 992> **NOTE**<br> 993> This API is supported since API version 8. 994> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCachedGnssLocationsSize](js-apis-geoLocationManager.md#geolocationmanagergetcachedgnsslocationssize). 995 996**Required permissions**: ohos.permission.LOCATION 997 998**System capability**: SystemCapability.Location.Location.Gnss 999 1000**Parameters** 1001 1002 | Name| Type| Mandatory| Description| 1003 | -------- | -------- | -------- | -------- | 1004 | callback | AsyncCallback<number> | Yes| Callback used to return the number of cached GNSS locations. | 1005 1006**Example** 1007 1008 ```ts 1009 import geolocation from '@ohos.geolocation'; 1010 geolocation.getCachedGnssLocationsSize((err, size) => { 1011 if (err) { 1012 console.log('getCachedGnssLocationsSize: err=' + JSON.stringify(err)); 1013 } 1014 if (size) { 1015 console.log('getCachedGnssLocationsSize: size=' + JSON.stringify(size)); 1016 } 1017 }); 1018 ``` 1019 1020 1021## geolocation.getCachedGnssLocationsSize<sup>(deprecated)</sup> 1022 1023getCachedGnssLocationsSize(): Promise<number>; 1024 1025Obtains the number of cached GNSS locations. 1026 1027> **NOTE**<br> 1028> This API is supported since API version 8. 1029> This API is deprecated since API version 9. You are advised to use [geoLocationManager.getCachedGnssLocationsSize](js-apis-geoLocationManager.md#geolocationmanagergetcachedgnsslocationssize-1). 1030 1031**Required permissions**: ohos.permission.LOCATION 1032 1033**System capability**: SystemCapability.Location.Location.Gnss 1034 1035**Return value** 1036 1037 | Name| Type| Mandatory| Description| 1038 | -------- | -------- | -------- | -------- | 1039 | Promise<number> | number|NA|Promise used to return the number of cached GNSS locations.| 1040 1041**Example** 1042 1043 ```ts 1044 import geolocation from '@ohos.geolocation'; 1045 geolocation.getCachedGnssLocationsSize().then((result) => { 1046 console.log('promise, getCachedGnssLocationsSize: ' + JSON.stringify(result)); 1047 }); 1048 ``` 1049 1050 1051## geolocation.flushCachedGnssLocations<sup>(deprecated)</sup> 1052 1053flushCachedGnssLocations(callback: AsyncCallback<boolean>): void; 1054 1055Obtains all cached GNSS locations and clears the GNSS cache queue. 1056 1057> **NOTE**<br> 1058> This API is supported since API version 8. 1059> This API is deprecated since API version 9. You are advised to use [geoLocationManager.flushCachedGnssLocations](js-apis-geoLocationManager.md#geolocationmanagerflushcachedgnsslocations). 1060 1061**Required permissions**: ohos.permission.LOCATION 1062 1063**System capability**: SystemCapability.Location.Location.Gnss 1064 1065**Parameters** 1066 1067 | Name| Type| Mandatory| Description| 1068 | -------- | -------- | -------- | -------- | 1069 | callback | AsyncCallback<boolean> | Yes| Callback used to return the operation result.| 1070 1071**Example** 1072 1073 ```ts 1074 import geolocation from '@ohos.geolocation'; 1075 geolocation.flushCachedGnssLocations((err, result) => { 1076 if (err) { 1077 console.log('flushCachedGnssLocations: err=' + JSON.stringify(err)); 1078 } 1079 if (result) { 1080 console.log('flushCachedGnssLocations: result=' + JSON.stringify(result)); 1081 } 1082 }); 1083 ``` 1084 1085 1086## geolocation.flushCachedGnssLocations<sup>(deprecated)</sup> 1087 1088flushCachedGnssLocations(): Promise<boolean>; 1089 1090Obtains all cached GNSS locations and clears the GNSS cache queue. 1091 1092> **NOTE**<br> 1093> This API is supported since API version 8. 1094> This API is deprecated since API version 9. You are advised to use [geoLocationManager.flushCachedGnssLocations](js-apis-geoLocationManager.md#geolocationmanagerflushcachedgnsslocations-1). 1095 1096**Required permissions**: ohos.permission.LOCATION 1097 1098**System capability**: SystemCapability.Location.Location.Gnss 1099 1100**Return value** 1101 1102 | Name| Type| Mandatory| Description| 1103 | -------- | -------- | -------- | -------- | 1104 | Promise<boolean> |boolean|NA| Promise used to return the operation result.| 1105 1106**Example** 1107 1108 ```ts 1109 import geolocation from '@ohos.geolocation'; 1110 geolocation.flushCachedGnssLocations().then((result) => { 1111 console.log('promise, flushCachedGnssLocations: ' + JSON.stringify(result)); 1112 }); 1113 ``` 1114 1115 1116## geolocation.sendCommand<sup>(deprecated)</sup> 1117 1118sendCommand(command: LocationCommand, callback: AsyncCallback<boolean>): void; 1119 1120Sends an extended command to the location subsystem. 1121 1122> **NOTE**<br> 1123> This API is supported since API version 8. 1124> This API is deprecated since API version 9. You are advised to use [geoLocationManager.sendCommand](js-apis-geoLocationManager.md#geolocationmanagersendcommand). 1125 1126**Required permissions**: ohos.permission.LOCATION 1127 1128**System capability**: SystemCapability.Location.Location.Core 1129 1130**Parameters** 1131 1132 | Name| Type| Mandatory| Description| 1133 | -------- | -------- | -------- | -------- | 1134 | command | [LocationCommand](#locationcommanddeprecated) | Yes| Extended command (string) to be sent.| 1135 | callback | AsyncCallback<boolean> | Yes| Callback used to return the operation result.| 1136 1137**Example** 1138 1139 ```ts 1140 import geolocation from '@ohos.geolocation'; 1141 let requestInfo = {'scenario': 0x301, 'command': "command_1"}; 1142 geolocation.sendCommand(requestInfo, (err, result) => { 1143 if (err) { 1144 console.log('sendCommand: err=' + JSON.stringify(err)); 1145 } 1146 if (result) { 1147 console.log('sendCommand: result=' + JSON.stringify(result)); 1148 } 1149 }); 1150 ``` 1151 1152 1153## geolocation.sendCommand<sup>(deprecated)</sup> 1154 1155sendCommand(command: LocationCommand): Promise<boolean>; 1156 1157Sends an extended command to the location subsystem. 1158 1159> **NOTE**<br> 1160> This API is supported since API version 8. 1161> This API is deprecated since API version 9. You are advised to use [geoLocationManager.sendCommand](js-apis-geoLocationManager.md#geolocationmanagersendcommand). 1162 1163**Required permissions**: ohos.permission.LOCATION 1164 1165**System capability**: SystemCapability.Location.Location.Core 1166 1167**Parameters** 1168 1169 | Name| Type| Mandatory| Description| 1170 | -------- | -------- | -------- | -------- | 1171 | command | [LocationCommand](#locationcommanddeprecated) | Yes| Extended command (string) to be sent.| 1172 1173**Return value** 1174 1175 | Name| Type| Mandatory| Description| 1176 | -------- | -------- | -------- | -------- | 1177 | Promise<boolean> |boolean|NA| Callback used to return the operation result.| 1178 1179**Example** 1180 1181 ```ts 1182 import geolocation from '@ohos.geolocation'; 1183 let requestInfo = {'scenario': 0x301, 'command': "command_1"}; 1184 geolocation.sendCommand(requestInfo).then((result) => { 1185 console.log('promise, sendCommand: ' + JSON.stringify(result)); 1186 }); 1187 ``` 1188 1189 1190## ReverseGeoCodeRequest<sup>(deprecated)</sup> 1191 1192Defines a reverse geocoding request. 1193 1194> **NOTE**<br> 1195> This API is deprecated since API version 9. You are advised to use [geoLocationManager.ReverseGeoCodeRequest](js-apis-geoLocationManager.md#reversegeocoderequest). 1196 1197**Required permissions**: ohos.permission.LOCATION 1198 1199**System capability**: SystemCapability.Location.Location.Geocoder 1200 1201| Name| Type| Readable| Writable| Description| 1202| -------- | -------- | -------- | -------- | -------- | 1203| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.| 1204| 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**.| 1205| 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**.| 1206| 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.| 1207 1208 1209## GeoCodeRequest<sup>(deprecated)</sup> 1210 1211Defines a geocoding request. 1212 1213> **NOTE**<br> 1214> This API is deprecated since API version 9. You are advised to use [geoLocationManager.GeoCodeRequest](js-apis-geoLocationManager.md#geocoderequest). 1215 1216**Required permissions**: ohos.permission.LOCATION 1217 1218**System capability**: SystemCapability.Location.Location.Geocoder 1219 1220| Name| Type| Readable|Writable| Description| 1221| -------- | -------- | -------- | -------- | -------- | 1222| locale | string | Yes| Yes| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.| 1223| description | string | Yes| Yes| Location description, for example, **No. xx, xx Road, Pudong New District, Shanghai**.| 1224| 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.| 1225| 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**.| 1226| minLongitude | number | Yes| Yes| Minimum longitude. The value ranges from **-180** to **180**.| 1227| maxLatitude | number | Yes| Yes| Maximum latitude. The value ranges from **-90** to **90**.| 1228| maxLongitude | number | Yes| Yes| Maximum longitude. The value ranges from **-180** to **180**.| 1229 1230 1231## GeoAddress<sup>(deprecated)</sup> 1232 1233Defines a geographic location. 1234 1235> **NOTE**<br> 1236> This API is deprecated since API version 9. You are advised to use [geoLocationManager.GeoAddress](js-apis-geoLocationManager.md#geoaddress). 1237 1238**Required permissions**: ohos.permission.LOCATION 1239 1240**System capability**: SystemCapability.Location.Location.Geocoder 1241 1242| Name| Type| Readable|Writable| Description| 1243| -------- | -------- | -------- | -------- | -------- | 1244| 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**.| 1245| 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**.| 1246| locale<sup>7+</sup> | string | Yes| No| Language used for the location description. **zh** indicates Chinese, and **en** indicates English.| 1247| placeName<sup>7+</sup> | string | Yes| No| Landmark of the location.| 1248| countryCode<sup>7+</sup> | string | Yes| No| Country code.| 1249| countryName<sup>7+</sup> | string | Yes| No| Country name.| 1250| administrativeArea<sup>7+</sup> | string | Yes| No| Administrative region name.| 1251| subAdministrativeArea<sup>7+</sup> | string | Yes| No| Sub-administrative region name.| 1252| locality<sup>7+</sup> | string | Yes| No| Locality information.| 1253| subLocality<sup>7+</sup> | string | Yes| No| Sub-locality information.| 1254| roadName<sup>7+</sup> | string | Yes| No| Road name.| 1255| subRoadName<sup>7+</sup> | string | Yes| No| Auxiliary road information.| 1256| premises<sup>7+</sup> | string | Yes| No| House information.| 1257| postalCode<sup>7+</sup> | string | Yes| No| Postal code.| 1258| phoneNumber<sup>7+</sup> | string | Yes| No| Phone number.| 1259| addressUrl<sup>7+</sup> | string | Yes| No| Website URL.| 1260| descriptions<sup>7+</sup> | Array<string> | Yes| No| Additional descriptions.| 1261| 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.| 1262 1263 1264## LocationRequest<sup>(deprecated)</sup> 1265 1266Defines a location request. 1267 1268> **NOTE**<br> 1269> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationRequest](js-apis-geoLocationManager.md#locationrequest). 1270 1271**Required permissions**: ohos.permission.LOCATION 1272 1273**System capability**: SystemCapability.Location.Location.Core 1274 1275| Name| Type| Readable|Writable| Description| 1276| -------- | -------- | -------- | -------- | -------- | 1277| priority | [LocationRequestPriority](#locationrequestprioritydeprecated) | Yes| Yes| Priority of the location request. For details about the value range, see [LocationRequestPriority](#locationrequestprioritydeprecated).| 1278| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated) | Yes| Yes| Scenario of the location request. For details about the value range, see [LocationRequestScenario](#locationrequestscenariodeprecated).| 1279| timeInterval | number | Yes| Yes| Time interval at which location information is reported, in seconds. The value must be greater than **0**.| 1280| distanceInterval | number | Yes| Yes| Distance interval at which location information is reported. The value must be greater than **0**, in meters.| 1281| 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**.| 1282 1283 1284## CurrentLocationRequest<sup>(deprecated)</sup> 1285 1286Defines the current location request. 1287 1288> **NOTE**<br> 1289> This API is deprecated since API version 9. You are advised to use [geoLocationManager.CurrentLocationRequest](js-apis-geoLocationManager.md#currentlocationrequest). 1290 1291**Required permissions**: ohos.permission.LOCATION 1292 1293**System capability**: SystemCapability.Location.Location.Core 1294 1295| Name| Type| Readable|Writable| Description| 1296| -------- | -------- | -------- | -------- | -------- | 1297| priority | [LocationRequestPriority](#locationrequestprioritydeprecated) | Yes| Yes| Priority of the location request. For details about the value range, see [LocationRequestPriority](#locationrequestprioritydeprecated).| 1298| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated) | Yes| Yes| Scenario of the location request. For details about the value range, see [LocationRequestScenario](#locationrequestscenariodeprecated).| 1299| 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**.| 1300| timeoutMs | number | Yes| Yes| Timeout duration, in milliseconds. The minimum value is **1000**. The value must be greater than or equal to **1000**.| 1301 1302 1303## SatelliteStatusInfo<sup>(deprecated)</sup> 1304 1305Defines the satellite status information. 1306 1307> **NOTE**<br> 1308> This API is supported since API version 8. 1309> This API is deprecated since API version 9. You are advised to use [geoLocationManager.SatelliteStatusInfo](js-apis-geoLocationManager.md#satellitestatusinfo). 1310 1311**Required permissions**: ohos.permission.LOCATION 1312 1313**System capability**: SystemCapability.Location.Location.Gnss 1314 1315| Name| Type| Readable|Writable| Description| 1316| -------- | -------- | -------- | -------- | -------- | 1317| satellitesNumber | number | Yes| No| Number of satellites. The value must be greater than or equal to **0**.| 1318| satelliteIds | Array<number> | Yes| No| Array of satellite IDs. The value must be greater than or equal to **0**.| 1319| carrierToNoiseDensitys | Array<number> | Yes| No| Carrier-to-noise density ratio, that is, **cn0**. The value must be greater than **0**.| 1320| altitudes | Array<number> | Yes| No| Satellite altitude angle information. The value ranges from **-90** to **90**, in degrees.| 1321| azimuths | Array<number> | Yes| No| Azimuth information. The value ranges from **0** to **360**, in degrees.| 1322| carrierFrequencies | Array<number> | Yes| No| Carrier frequency. The value must be greater than or equal to **0**, in Hz.| 1323 1324 1325## CachedGnssLocationsRequest<sup>(deprecated)</sup> 1326 1327Represents a request for reporting cached GNSS locations. 1328 1329> **NOTE**<br> 1330> This API is supported since API version 8. 1331> This API is deprecated since API version 9. You are advised to use [geoLocationManager.CachedGnssLocationsRequest](js-apis-geoLocationManager.md#cachedgnsslocationsrequest). 1332 1333**Required permissions**: ohos.permission.LOCATION 1334 1335**System capability**: SystemCapability.Location.Location.Gnss 1336 1337| Name| Type| Readable|Writable| Description| 1338| -------- | -------- | -------- | -------- | -------- | 1339| reportingPeriodSec | number | Yes| Yes| Interval for reporting the cached GNSS locations, in milliseconds. The value must be greater than **0**.| 1340| 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.| 1341 1342 1343## Geofence<sup>(deprecated)</sup> 1344 1345Defines a GNSS geofence. Currently, only circular geofences are supported. 1346 1347> **NOTE**<br> 1348> This API is supported since API version 8. 1349> This API is deprecated since API version 9. You are advised to use [geoLocationManager.Geofence](js-apis-geoLocationManager.md#geofence). 1350 1351**Required permissions**: ohos.permission.LOCATION 1352 1353**System capability**: SystemCapability.Location.Location.Geofence 1354 1355| Name| Type| Readable|Writable| Description| 1356| -------- | -------- | -------- | -------- | -------- | 1357| latitude | number | Yes| Yes|Latitude information. The value ranges from **-90** to **90**.| 1358| longitude | number | Yes|Yes| Longitude information. The value ranges from **-180** to **180**.| 1359| radius | number | Yes|Yes| Radius of a circular geofence. The value must be greater than **0**, in meters.| 1360| expiration | number | Yes|Yes| Expiration period of a geofence, in milliseconds. The value must be greater than **0**.| 1361 1362 1363## GeofenceRequest<sup>(deprecated)</sup> 1364 1365Represents a GNSS geofencing request. 1366 1367> **NOTE**<br> 1368> This API is supported since API version 8. 1369> This API is deprecated since API version 9. You are advised to use [geoLocationManager.GeofenceRequest](js-apis-geoLocationManager.md#geofencerequest). 1370 1371**Required permissions**: ohos.permission.LOCATION 1372 1373**System capability**: SystemCapability.Location.Location.Geofence 1374 1375| Name| Type| Readable|Writable| Description| 1376| -------- | -------- | -------- | -------- | -------- | 1377| priority | [LocationRequestPriority](#locationrequestprioritydeprecated) | Yes| Yes | Priority of the location information.| 1378| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated) | Yes| Yes | Location scenario.| 1379| geofence | [Geofence](#geofencedeprecated)| Yes| Yes | Geofence information.| 1380 1381 1382## LocationCommand<sup>(deprecated)</sup> 1383 1384Defines an extended command. 1385 1386> **NOTE**<br> 1387> This API is supported since API version 8. 1388> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationCommand](js-apis-geoLocationManager.md#locationcommand). 1389 1390**Required permissions**: ohos.permission.LOCATION 1391 1392**System capability**: SystemCapability.Location.Location.Core 1393 1394| Name| Type| Readable|Writable| Description| 1395| -------- | -------- | -------- | -------- | -------- | 1396| scenario | [LocationRequestScenario](#locationrequestscenariodeprecated) | Yes| Yes | Location scenario.| 1397| command | string | Yes| Yes | Extended command, in the string format.| 1398 1399 1400## Location<sup>(deprecated)</sup> 1401 1402Defines a location. 1403 1404> **NOTE**<br> 1405> This API is deprecated since API version 9. You are advised to use [geoLocationManager.Location](js-apis-geoLocationManager.md#location). 1406 1407**Required permissions**: ohos.permission.LOCATION 1408 1409**System capability**: SystemCapability.Location.Location.Core 1410 1411| Name| Type| Readable|Writable| Description| 1412| -------- | -------- | -------- | -------- | -------- | 1413| 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**.| 1414| 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**.| 1415| altitude<sup>7+</sup> | number | Yes| No| Location altitude, in meters.| 1416| accuracy<sup>7+</sup> | number | Yes| No| Location accuracy, in meters.| 1417| speed<sup>7+</sup> | number | Yes| No| Speed, in m/s.| 1418| timeStamp<sup>7+</sup> | number | Yes| No| Location timestamp in the UTC format.| 1419| direction<sup>7+</sup> | number | Yes| No| Direction information. The value ranges from **0** to **360**, in degrees.| 1420| timeSinceBoot<sup>7+</sup> | number | Yes| No| Location timestamp since boot.| 1421| additions<sup>7+</sup> | Array<string> | Yes| No| Additional description.| 1422| additionSize<sup>7+</sup> | number | Yes| No| Number of additional descriptions. The value must be greater than or equal to **0**.| 1423 1424 1425## LocationPrivacyType<sup>(deprecated)</sup> 1426 1427Defines the privacy statement type. 1428 1429> **NOTE**<br> 1430> This API is supported since API version 8. 1431> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationPrivacyType](js-apis-geoLocationManager.md#locationprivacytype). 1432 1433**Required permissions**: ohos.permission.LOCATION 1434 1435**System capability**: SystemCapability.Location.Location.Core 1436 1437| Name| Value| Description| 1438| -------- | -------- | -------- | 1439| OTHERS | 0 | Other scenarios. Reserved field.| 1440| STARTUP | 1 | Privacy statement displayed in the startup wizard. | 1441| CORE_LOCATION | 2 | Privacy statement displayed when enabling the location service.| 1442 1443 1444## LocationRequestPriority<sup>(deprecated)</sup> 1445 1446Sets the priority of the location request. 1447 1448> **NOTE**<br> 1449> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationRequestPriority](js-apis-geoLocationManager.md#locationrequestpriority). 1450 1451**Required permissions**: ohos.permission.LOCATION 1452 1453**System capability**: SystemCapability.Location.Location.Core 1454 1455| Name| Value| Description| 1456| -------- | -------- | -------- | 1457| UNSET | 0x200 | Priority unspecified.<br>If this option is used, [LocationRequestPriority](#locationrequestprioritydeprecated) is invalid.| 1458| 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.| 1459| 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.| 1460| 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.| 1461 1462 1463## LocationRequestScenario<sup>(deprecated)</sup> 1464 1465 Sets the scenario of the location request. 1466 1467> **NOTE**<br> 1468> This API is deprecated since API version 9. You are advised to use [geoLocationManager.LocationRequestScenario](js-apis-geoLocationManager.md#locationrequestscenario). 1469 1470**Required permissions**: ohos.permission.LOCATION 1471 1472**System capability**: SystemCapability.Location.Location.Core 1473 1474| Name| Value| Description| 1475| -------- | -------- | -------- | 1476| UNSET | 0x300 | Scenario unspecified.<br>If this option is used, [LocationRequestScenario](#locationrequestscenariodeprecated) is invalid.| 1477| 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.| 1478| 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.| 1479| 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.| 1480| 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.| 1481| 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.| 1482 1483 1484## GeoLocationErrorCode<sup>(deprecated)</sup> 1485 1486Enumerates error codes of the location service. 1487 1488> **NOTE**<br> 1489> This API is deprecated since API version 9. You are advised to use [geoLocationManager](../errorcodes/errorcode-geoLocationManager.md). 1490 1491**Required permissions**: ohos.permission.LOCATION 1492 1493**System capability**: SystemCapability.Location.Location.Core 1494 1495| Name| Value| Description| 1496| -------- | -------- | -------- | 1497| INPUT_PARAMS_ERROR<sup>7+</sup> | 101 | Incorrect input parameters.| 1498| REVERSE_GEOCODE_ERROR<sup>7+</sup> | 102 | Failed to call the reverse geocoding API.| 1499| GEOCODE_ERROR<sup>7+</sup> | 103 | Failed to call the geocoding API.| 1500| LOCATOR_ERROR<sup>7+</sup> | 104 | Failed to obtain the location.| 1501| LOCATION_SWITCH_ERROR<sup>7+</sup> | 105 | Failed to change the location service switch.| 1502| LAST_KNOWN_LOCATION_ERROR<sup>7+</sup> | 106 | Failed to obtain the previous location.| 1503| LOCATION_REQUEST_TIMEOUT_ERROR<sup>7+</sup> | 107 | Failed to obtain the location within the specified time.| 1504