1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15import { AsyncCallback, Callback } from './basic'; 16import { WantAgent } from './@ohos.wantAgent'; 17 18 /** 19 * Provides interfaces for initiating location requests, ending the location service, 20 * and obtaining the location result cached by the system. 21 * 22 * @since 7 23 * @syscap SystemCapability.Location.Location.Core 24 * @permission ohos.permission.LOCATION 25 * @deprecated since 9 26 */ 27declare namespace geolocation { 28 /** 29 * subscribe location changed 30 * 31 * @since 7 32 * @syscap SystemCapability.Location.Location.Core 33 * @permission ohos.permission.LOCATION 34 * @param request Indicates the location request parameters. 35 * @param callback Indicates the callback for reporting the location result. 36 * @deprecated since 9 37 * @useinstead ohos.geoLocationManager/geoLocationManager.on#event:locationChange 38 */ 39 function on(type: 'locationChange', request: LocationRequest, callback: Callback<Location>): void; 40 41 /** 42 * unsubscribe location changed 43 * 44 * @since 7 45 * @syscap SystemCapability.Location.Location.Core 46 * @permission ohos.permission.LOCATION 47 * @param callback Indicates the callback for reporting the location result. 48 * @deprecated since 9 49 * @useinstead ohos.geoLocationManager/geoLocationManager.off#event:locationChange 50 */ 51 function off(type: 'locationChange', callback?: Callback<Location>): void; 52 53 /** 54 * subscribe location switch changed 55 * 56 * @since 7 57 * @syscap SystemCapability.Location.Location.Core 58 * @permission ohos.permission.LOCATION 59 * @param callback Indicates the callback for reporting the location result. 60 * @deprecated since 9 61 * @useinstead ohos.geoLocationManager/geoLocationManager.on#event:locationEnabledChange 62 */ 63 function on(type: 'locationServiceState', callback: Callback<boolean>): void; 64 65 /** 66 * unsubscribe location switch changed 67 * 68 * @since 7 69 * @syscap SystemCapability.Location.Location.Core 70 * @permission ohos.permission.LOCATION 71 * @param callback Indicates the callback for reporting the location result. 72 * @deprecated since 9 73 * @useinstead ohos.geoLocationManager/geoLocationManager.off#event:locationEnabledChange 74 */ 75 function off(type: 'locationServiceState', callback?: Callback<boolean>): void; 76 77 /** 78 * subscribe to cache GNSS locations update messages 79 * 80 * @since 8 81 * @syscap SystemCapability.Location.Location.Gnss 82 * @permission ohos.permission.LOCATION 83 * @param request Indicates the cached GNSS locations request parameters. 84 * @param callback Indicates the callback for reporting the cached GNSS locations. 85 * @deprecated since 9 86 * @useinstead ohos.geoLocationManager/geoLocationManager.on#event:cachedGnssLocationsChange 87 */ 88 function on(type: 'cachedGnssLocationsReporting', request: CachedGnssLocationsRequest, callback: Callback<Array<Location>>): void; 89 90 /** 91 * unsubscribe to cache GNSS locations update messages 92 * 93 * @since 8 94 * @syscap SystemCapability.Location.Location.Gnss 95 * @permission ohos.permission.LOCATION 96 * @param callback Indicates the callback for reporting the cached gnss locations. 97 * @deprecated since 9 98 * @useinstead ohos.geoLocationManager/geoLocationManager.off#event:cachedGnssLocationsChange 99 */ 100 function off(type: 'cachedGnssLocationsReporting', callback?: Callback<Array<Location>>): void; 101 102 /** 103 * subscribe gnss status changed 104 * 105 * @since 8 106 * @syscap SystemCapability.Location.Location.Gnss 107 * @permission ohos.permission.LOCATION 108 * @param callback Indicates the callback for reporting the gnss status change. 109 * @deprecated since 9 110 * @useinstead ohos.geoLocationManager/geoLocationManager.on#event:satelliteStatusChange 111 */ 112 function on(type: 'gnssStatusChange', callback: Callback<SatelliteStatusInfo>): void; 113 114 /** 115 * unsubscribe gnss status changed 116 * 117 * @since 8 118 * @syscap SystemCapability.Location.Location.Gnss 119 * @permission ohos.permission.LOCATION 120 * @param callback Indicates the callback for reporting the gnss status change. 121 * @deprecated since 9 122 * @useinstead ohos.geoLocationManager/geoLocationManager.off#event:satelliteStatusChange 123 */ 124 function off(type: 'gnssStatusChange', callback?: Callback<SatelliteStatusInfo>): void; 125 126 /** 127 * subscribe nmea message changed 128 * 129 * @since 8 130 * @syscap SystemCapability.Location.Location.Gnss 131 * @permission ohos.permission.LOCATION 132 * @param callback Indicates the callback for reporting the nmea message. 133 * @deprecated since 9 134 * @useinstead ohos.geoLocationManager/geoLocationManager.on#event:nmeaMessage 135 */ 136 function on(type: 'nmeaMessageChange', callback: Callback<string>): void; 137 138 /** 139 * unsubscribe nmea message changed 140 * 141 * @since 8 142 * @syscap SystemCapability.Location.Location.Gnss 143 * @permission ohos.permission.LOCATION 144 * @param callback Indicates the callback for reporting the nmea message. 145 * @deprecated since 9 146 * @useinstead ohos.geoLocationManager/geoLocationManager.off#event:nmeaMessage 147 */ 148 function off(type: 'nmeaMessageChange', callback?: Callback<string>): void; 149 150 /** 151 * add a geofence and subscribe geo fence status changed 152 * 153 * @since 8 154 * @syscap SystemCapability.Location.Location.Geofence 155 * @permission ohos.permission.LOCATION 156 * @param request Indicates the Geo-fence configuration parameters. 157 * @param callback Indicates the callback for reporting the fence status. 158 * @deprecated since 9 159 * @useinstead ohos.geoLocationManager/geoLocationManager.on#event:gnssFenceStatusChange 160 */ 161 function on(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void; 162 163 /** 164 * remove a geofence and unsubscribe geo fence status changed 165 * 166 * @since 8 167 * @syscap SystemCapability.Location.Location.Geofence 168 * @permission ohos.permission.LOCATION 169 * @param request Indicates the Geo-fence configuration parameters. 170 * @param callback Indicates the callback for reporting the remove fence result. 171 * @deprecated since 9 172 * @useinstead ohos.geoLocationManager/geoLocationManager.off#event:gnssFenceStatusChange 173 */ 174 function off(type: 'fenceStatusChange', request: GeofenceRequest, want: WantAgent): void; 175 176 /** 177 * obtain current location 178 * 179 * @since 7 180 * @syscap SystemCapability.Location.Location.Core 181 * @permission ohos.permission.LOCATION 182 * @param callback Indicates the callback for reporting the location result. 183 * @deprecated since 9 184 * @useinstead ohos.geoLocationManager/geoLocationManager.getCurrentLocation 185 */ 186 function getCurrentLocation(request: CurrentLocationRequest, callback: AsyncCallback<Location>): void; 187 function getCurrentLocation(callback: AsyncCallback<Location>): void; 188 function getCurrentLocation(request?: CurrentLocationRequest): Promise<Location>; 189 190 /** 191 * obtain last known location 192 * 193 * @since 7 194 * @syscap SystemCapability.Location.Location.Core 195 * @permission ohos.permission.LOCATION 196 * @param callback Indicates the callback for reporting the location result. 197 * @deprecated since 9 198 * @useinstead ohos.geoLocationManager/geoLocationManager.getLastLocation 199 */ 200 function getLastLocation(callback: AsyncCallback<Location>): void; 201 function getLastLocation(): Promise<Location>; 202 203 /** 204 * obtain current location switch status 205 * 206 * @since 7 207 * @syscap SystemCapability.Location.Location.Core 208 * @permission ohos.permission.LOCATION 209 * @param callback Indicates the callback for reporting the location switch result. 210 * @deprecated since 9 211 * @useinstead ohos.geoLocationManager/geoLocationManager.isLocationEnabled 212 */ 213 function isLocationEnabled(callback: AsyncCallback<boolean>): void; 214 function isLocationEnabled(): Promise<boolean>; 215 216 /** 217 * request enable location 218 * 219 * @since 7 220 * @syscap SystemCapability.Location.Location.Core 221 * @permission ohos.permission.LOCATION 222 * @param callback Indicates the callback for reporting the location switch status. 223 * @deprecated since 9 224 */ 225 function requestEnableLocation(callback: AsyncCallback<boolean>): void; 226 function requestEnableLocation(): Promise<boolean>; 227 228 /** 229 * obtain address info from location 230 * 231 * @since 7 232 * @syscap SystemCapability.Location.Location.Geocoder 233 * @permission ohos.permission.LOCATION 234 * @param callback Indicates the callback for reporting the address info. 235 * @deprecated since 9 236 * @useinstead ohos.geoLocationManager/geoLocationManager.getAddressesFromLocation 237 */ 238 function getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void; 239 function getAddressesFromLocation(request: ReverseGeoCodeRequest): Promise<Array<GeoAddress>>; 240 241 /** 242 * obtain latitude and longitude info from location address 243 * 244 * @since 7 245 * @syscap SystemCapability.Location.Location.Geocoder 246 * @permission ohos.permission.LOCATION 247 * @param callback Indicates the callback for reporting the latitude and longitude result. 248 * @deprecated since 9 249 * @useinstead ohos.geoLocationManager/geoLocationManager.getAddressesFromLocationName 250 */ 251 function getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void; 252 function getAddressesFromLocationName(request: GeoCodeRequest): Promise<Array<GeoAddress>>; 253 254 /** 255 * obtain geocode service status 256 * 257 * @since 7 258 * @syscap SystemCapability.Location.Location.Geocoder 259 * @permission ohos.permission.LOCATION 260 * @param callback Indicates the callback for reporting the geocode service status. 261 * @deprecated since 9 262 * @useinstead ohos.geoLocationManager/geoLocationManager.isGeocoderAvailable 263 */ 264 function isGeoServiceAvailable(callback: AsyncCallback<boolean>): void; 265 function isGeoServiceAvailable(): Promise<boolean>; 266 267 /** 268 * obtain the number of cached GNSS locations reported at a time 269 * 270 * @since 8 271 * @syscap SystemCapability.Location.Location.Gnss 272 * @permission ohos.permission.LOCATION 273 * @param callback Indicates the callback for reporting the cached GNSS locations size. 274 * @deprecated since 9 275 * @useinstead ohos.geoLocationManager/geoLocationManager.getCachedGnssLocationsSize 276 */ 277 function getCachedGnssLocationsSize(callback: AsyncCallback<number>): void; 278 function getCachedGnssLocationsSize(): Promise<number>; 279 280 /** 281 * all prepared GNSS locations are returned to the application through the callback function, 282 * and the bottom-layer buffer is cleared. 283 * 284 * @since 8 285 * @syscap SystemCapability.Location.Location.Gnss 286 * @permission ohos.permission.LOCATION 287 * @param callback Indicates the callback for reporting the result. 288 * @deprecated since 9 289 * @useinstead ohos.geoLocationManager/geoLocationManager.flushCachedGnssLocations 290 */ 291 function flushCachedGnssLocations(callback: AsyncCallback<boolean>): void; 292 function flushCachedGnssLocations(): Promise<boolean>; 293 294 /** 295 * send extended commands to location subsystem. 296 * 297 * @since 8 298 * @syscap SystemCapability.Location.Location.Core 299 * @permission ohos.permission.LOCATION 300 * @param command Indicates the extended Command Message Body. 301 * @param callback Indicates the callback for reporting the send command result. 302 * @deprecated since 9 303 * @useinstead ohos.geoLocationManager/geoLocationManager.sendCommand 304 */ 305 function sendCommand(command: LocationCommand, callback: AsyncCallback<boolean>): void; 306 function sendCommand(command: LocationCommand): Promise<boolean>; 307 308 /** 309 * satellite status information 310 * 311 * @since 8 312 * @syscap SystemCapability.Location.Location.Gnss 313 * @permission ohos.permission.LOCATION 314 * @deprecated since 9 315 * @useinstead ohos.geoLocationManager/geoLocationManager.SatelliteStatusInfo 316 */ 317 export interface SatelliteStatusInfo { 318 satellitesNumber: number; 319 satelliteIds: Array<number>; 320 carrierToNoiseDensitys: Array<number>; 321 altitudes: Array<number>; 322 azimuths: Array<number>; 323 carrierFrequencies: Array<number>; 324 } 325 326 /** 327 * parameters for requesting to report cache location information 328 * 329 * @since 8 330 * @syscap SystemCapability.Location.Location.Gnss 331 * @permission ohos.permission.LOCATION 332 * @deprecated since 9 333 * @useinstead ohos.geoLocationManager/geoLocationManager.CachedGnssLocationsRequest 334 */ 335 export interface CachedGnssLocationsRequest { 336 reportingPeriodSec: number; 337 wakeUpCacheQueueFull: boolean; 338 } 339 340 /** 341 * configuring parameters in geo fence requests 342 * 343 * @since 8 344 * @syscap SystemCapability.Location.Location.Geofence 345 * @permission ohos.permission.LOCATION 346 * @deprecated since 9 347 * @useinstead ohos.geoLocationManager/geoLocationManager.GeofenceRequest 348 */ 349 export interface GeofenceRequest { 350 priority: LocationRequestPriority; 351 scenario: LocationRequestScenario; 352 geofence: Geofence; 353 } 354 355 /** 356 * configuring parameters in geo fence requests 357 * 358 * @since 8 359 * @syscap SystemCapability.Location.Location.Geofence 360 * @permission ohos.permission.LOCATION 361 * @deprecated since 9 362 * @useinstead ohos.geoLocationManager/geoLocationManager.Geofence 363 */ 364 export interface Geofence { 365 latitude: number; 366 longitude: number; 367 radius: number; 368 expiration: number; 369 } 370 371 /** 372 * configuring parameters in reverse geocode requests 373 * 374 * @since 7 375 * @syscap SystemCapability.Location.Location.Geocoder 376 * @permission ohos.permission.LOCATION 377 * @deprecated since 9 378 * @useinstead ohos.geoLocationManager/geoLocationManager.ReverseGeoCodeRequest 379 */ 380 export interface ReverseGeoCodeRequest { 381 locale?: string; 382 latitude: number; 383 longitude: number; 384 maxItems?: number; 385 } 386 387 /** 388 * configuring parameters in geocode requests 389 * 390 * @since 7 391 * @syscap SystemCapability.Location.Location.Geocoder 392 * @permission ohos.permission.LOCATION 393 * @deprecated since 9 394 * @useinstead ohos.geoLocationManager/geoLocationManager.GeoCodeRequest 395 */ 396 export interface GeoCodeRequest { 397 locale?: string; 398 description: string; 399 maxItems?: number; 400 minLatitude?: number; 401 minLongitude?: number; 402 maxLatitude?: number; 403 maxLongitude?: number; 404 } 405 406 /** 407 * data struct describes geographic locations. 408 * 409 * @since 7 410 * @syscap SystemCapability.Location.Location.Geocoder 411 * @permission ohos.permission.LOCATION 412 * @deprecated since 9 413 * @useinstead ohos.geoLocationManager/geoLocationManager.GeoAddress 414 */ 415 export interface GeoAddress { 416 /** 417 * Indicates latitude information. 418 * A positive value indicates north latitude, 419 * and a negative value indicates south latitude. 420 * @since 7 421 */ 422 latitude?: number; 423 424 /** 425 * Indicates longitude information. 426 * A positive value indicates east longitude , 427 * and a negative value indicates west longitude . 428 * @since 7 429 */ 430 longitude?: number; 431 432 /** 433 * Indicates language used for the location description. 434 * zh indicates Chinese, and en indicates English. 435 * @since 7 436 */ 437 locale?: string; 438 439 /** 440 * Indicates landmark of the location. 441 * @since 7 442 */ 443 placeName?: string; 444 445 /** 446 * Indicates country code. 447 * @since 7 448 */ 449 countryCode?: string; 450 451 /** 452 * Indicates country name. 453 * @since 7 454 */ 455 countryName?: string; 456 457 /** 458 * Indicates administrative region name. 459 * @since 7 460 */ 461 administrativeArea?: string; 462 463 /** 464 * Indicates sub-administrative region name. 465 * @since 7 466 */ 467 subAdministrativeArea?: string; 468 469 /** 470 * Indicates locality information. 471 * @since 7 472 */ 473 locality?: string; 474 475 /** 476 * Indicates sub-locality information. 477 * @since 7 478 */ 479 subLocality?: string; 480 481 /** 482 * Indicates road name. 483 * @since 7 484 */ 485 roadName?: string; 486 487 /** 488 * Indicates auxiliary road information. 489 * @since 7 490 */ 491 subRoadName?: string; 492 493 /** 494 * Indicates house information. 495 * @since 7 496 */ 497 premises?: string; 498 499 /** 500 * Indicates postal code. 501 * @since 7 502 */ 503 postalCode?: string; 504 505 /** 506 * Indicates phone number. 507 * @since 7 508 */ 509 phoneNumber?: string; 510 511 /** 512 * Indicates website URL. 513 * @since 7 514 */ 515 addressUrl?: string; 516 517 /** 518 * Indicates additional information. 519 * @since 7 520 */ 521 descriptions?: Array<string>; 522 523 /** 524 * Indicates the amount of additional descriptive information. 525 * @since 7 526 */ 527 descriptionsSize?: number; 528 } 529 530 /** 531 * configuring parameters in location requests 532 * 533 * @since 7 534 * @syscap SystemCapability.Location.Location.Core 535 * @permission ohos.permission.LOCATION 536 * @deprecated since 9 537 * @useinstead ohos.geoLocationManager/geoLocationManager.LocationRequest 538 */ 539 export interface LocationRequest { 540 priority?: LocationRequestPriority; 541 scenario?: LocationRequestScenario; 542 timeInterval?: number; 543 distanceInterval?: number; 544 maxAccuracy?: number; 545 } 546 547 /** 548 * configuring parameters in current location requests 549 * 550 * @since 7 551 * @syscap SystemCapability.Location.Location.Core 552 * @permission ohos.permission.LOCATION 553 * @deprecated since 9 554 * @useinstead ohos.geoLocationManager/geoLocationManager.CurrentLocationRequest 555 */ 556 export interface CurrentLocationRequest { 557 priority?: LocationRequestPriority; 558 scenario?: LocationRequestScenario; 559 maxAccuracy?: number; 560 timeoutMs?: number; 561 } 562 563 /** 564 * provides information about geographic locations 565 * 566 * @since 7 567 * @syscap SystemCapability.Location.Location.Core 568 * @permission ohos.permission.LOCATION 569 * @deprecated since 9 570 * @useinstead ohos.geoLocationManager/geoLocationManager.Location 571 */ 572 export interface Location { 573 /** 574 * Indicates latitude information. 575 * A positive value indicates north latitude, 576 * and a negative value indicates south latitude. 577 * @since 7 578 */ 579 latitude: number; 580 581 /** 582 * Indicates Longitude information. 583 * A positive value indicates east longitude , 584 * and a negative value indicates west longitude . 585 * @since 7 586 */ 587 longitude: number; 588 589 /** 590 * Indicates location altitude, in meters. 591 * @since 7 592 */ 593 altitude: number; 594 595 /** 596 * Indicates location accuracy, in meters. 597 * @since 7 598 */ 599 accuracy: number; 600 601 /** 602 * Indicates speed, in m/s. 603 * @since 7 604 */ 605 speed: number; 606 607 /** 608 * Indicates location timestamp in the UTC format. 609 * @since 7 610 */ 611 timeStamp: number; 612 613 /** 614 * Indicates direction information. 615 * @since 7 616 */ 617 direction: number; 618 619 /** 620 * Indicates location timestamp since boot. 621 * @since 7 622 */ 623 timeSinceBoot: number; 624 625 /** 626 * Indicates additional information. 627 * @since 7 628 */ 629 additions?: Array<string>; 630 631 /** 632 * Indicates the amount of additional descriptive information. 633 * @since 7 634 */ 635 additionSize?: number; 636 } 637 638 /** 639 * enum for location priority 640 * 641 * @since 7 642 * @syscap SystemCapability.Location.Location.Core 643 * @permission ohos.permission.LOCATION 644 * @deprecated since 9 645 * @useinstead ohos.geoLocationManager/geoLocationManager.LocationRequestPriority 646 */ 647 export enum LocationRequestPriority { 648 UNSET = 0x200, 649 ACCURACY, 650 LOW_POWER, 651 FIRST_FIX, 652 } 653 654 /** 655 * enum for location scenario 656 * 657 * @since 7 658 * @syscap SystemCapability.Location.Location.Core 659 * @permission ohos.permission.LOCATION 660 * @deprecated since 9 661 * @useinstead ohos.geoLocationManager/geoLocationManager.LocationRequestScenario 662 */ 663 export enum LocationRequestScenario { 664 UNSET = 0x300, 665 NAVIGATION, 666 TRAJECTORY_TRACKING, 667 CAR_HAILING, 668 DAILY_LIFE_SERVICE, 669 NO_POWER, 670 } 671 672 /** 673 * enum for error code 674 * 675 * @since 7 676 * @syscap SystemCapability.Location.Location.Core 677 * @permission ohos.permission.LOCATION 678 * @deprecated since 9 679 */ 680 export enum GeoLocationErrorCode { 681 /** 682 * Indicates input parameter error. 683 * @since 7 684 */ 685 INPUT_PARAMS_ERROR, 686 687 /** 688 * Indicates reverse geocode query failed. 689 * @since 7 690 */ 691 REVERSE_GEOCODE_ERROR, 692 693 /** 694 * Indicates geocode query failed. 695 * @since 7 696 */ 697 GEOCODE_ERROR, 698 699 /** 700 * Indicates positioning failed. 701 * @since 7 702 */ 703 LOCATOR_ERROR, 704 705 /** 706 * Indicates operation failure caused by abnormal location switch. 707 * @since 7 708 */ 709 LOCATION_SWITCH_ERROR, 710 711 /** 712 * Indicates failed to get the last known location. 713 * @since 7 714 */ 715 LAST_KNOWN_LOCATION_ERROR, 716 717 /** 718 * Indicates location request timeout. 719 * @since 7 720 */ 721 LOCATION_REQUEST_TIMEOUT_ERROR, 722 } 723 724 /** 725 * enum for location privacy type 726 * 727 * @since 8 728 * @syscap SystemCapability.Location.Location.Core 729 * @permission ohos.permission.LOCATION 730 * @deprecated since 9 731 * @useinstead ohos.geoLocationManager/geoLocationManager.LocationPrivacyType 732 */ 733 export enum LocationPrivacyType { 734 OTHERS = 0, 735 STARTUP, 736 CORE_LOCATION, 737 } 738 739 /** 740 * Location subsystem command structure 741 * 742 * @since 8 743 * @syscap SystemCapability.Location.Location.Core 744 * @permission ohos.permission.LOCATION 745 * @deprecated since 9 746 * @useinstead ohos.geoLocationManager/geoLocationManager.LocationCommand 747 */ 748 export interface LocationCommand { 749 scenario: LocationRequestScenario; 750 command: string; 751 } 752} 753 754export default geolocation; 755