openharmony 鸿蒙 changelogs-geolocation

2023-02-03 浏览 (582)

Location Subsystem ChangeLog

cl.location.1 Migration of System APIs and APIs in API Version 9 to the New @ohos.geoLocationManager.d.ts

APIs in @ohos.geolocation.d.ts do not support throwing error codes. However, APIs in API version 9 and system APIs all need to support throwing error codes. To support this function, all system APIs and APIs in API version 9 in @ohos.geolocation.d.ts are migrated to the newly added @ohos.geoLocationManager.d.ts file, and corresponding error code description is added.

To use system APIs and APIs in API version 9 of the location subsystem, you need to import @ohos.geoLocationManager.

import geoLocationManager from '@ohos.geoLocationManager';

Change Impacts

System APIs and APIs in API version 9 are affected. To ensure normal use of these APIs, you need to import @ohos.geoLocationManager.

import geoLocationManager from '@ohos.geoLocationManager';

Other APIs are not affected.

Key API/Component Changes

ClassTypeDeclarationChange Type
geolocationnamespacedeclare namespacegeolocationMigrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationinterfaceexport interface ReverseGeocodingMockInfoMigrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationinterfaceexport interface LocationMockConfigMigrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationinterfaceexport interface CountryCodeMigrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationenumexport enum CountryCodeTypeMigrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocation.GeoAddressfieldisFromMock?: Boolean;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocation.LocationfieldisFromMock?: Boolean;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocation.GeoLocationErrorCodefieldNOT_SUPPORTED = 100Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocation.GeoLocationErrorCodefieldQUERY_COUNTRY_CODE_ERRORMigrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction on(type: 'countryCodeChange', callback: Callback<CountryCode>): void;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction off(type: 'countryCodeChange', callback?: Callback<CountryCode>): void;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction getCountryCode(callback: AsyncCallback<CountryCode>): void;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction getCountryCode(): Promise<CountryCode>;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction enableLocationMock(scenario: LocationRequestScenario, callback: AsyncCallback<void>): void;Deleted this API in API version 9.
geolocationmethodfunction enableLocationMock(callback: AsyncCallback<void>): void;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction enableLocationMock(scenario: LocationRequestScenario): Promise<void>;Deleted this API in API version 9.
geolocationmethodfunction enableLocationMock(): Promise<void>;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction disableLocationMock(scenario: LocationRequestScenario, callback: AsyncCallback<void>): void;Deleted this API in API version 9.
geolocationmethodfunction disableLocationMock(callback: AsyncCallback<void>): void;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction disableLocationMock(scenario: LocationRequestScenario): Promise<void>;Deleted this API in API version 9.
geolocationmethodfunction disableLocationMock(): Promise<void>;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction setMockedLocations(config: LocationMockConfig, callback: AsyncCallback<void>): void;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction setMockedLocations(config: LocationMockConfig): Promise<void>;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction enableReverseGeocodingMock(callback: AsyncCallback<void>): void;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction enableReverseGeocodingMock(): Promise<void>;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction disableReverseGeocodingMock(callback: AsyncCallback<void>): void;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction disableReverseGeocodingMock(): Promise<void>;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>, callback: AsyncCallback<void>): void;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>): Promise<void>;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction isLocationPrivacyConfirmed(type: LocationPrivacyType, callback: AsyncCallback<boolean>): void;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction isLocationPrivacyConfirmed(type: LocationPrivacyType): Promise<boolean>;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts.
geolocationmethodfunction setLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean, callback: AsyncCallback<boolean>): void;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts and changed the return value in the callback to void.
geolocationmethodfunction setLocationPrivacyConfirmStatus(type: LocationPrivacyType, isConfirmed: boolean): Promise<boolean>;Migrated this API in API version 9 to @ohos.geoLocationManager.d.ts and changed the return value in the promise to void.

(Optional) Adaptation Guide

The following uses enableLocation as an example to show how it is called in the new version:

import geoLocationManager from '@ohos.geoLocationManager';
try {
    geoLocationManager.enableLocation((err, data) => {
        if (err) {
            console.log('enableLocation: err=' + JSON.stringify(err));
        }
    });
} catch (err) {
    console.error("errCode:" + err.code + ",errMessage:" + err.message);
}

cl.location.2 Location Service Permission Change

From API version 9, the ohos.permission.APPROXIMATELY_LOCATION permission is added for obtaining the approximate location.

If you use API version 9 or later, you need to apply for both the ohos.permission.LOCATION and ohos.permission.APPROXIMATELY_LOCATION permissions. Applying for only the ohos.permission.LOCATION permission will fail.

Change Impacts

Applications using API versions earlier than 9 are not affected. For an application using API version 9 or later, the method for applying for the location permission is changed. The details are as follows:

Before 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.

The system provides the following location permissions:

  • ohos.permission.LOCATION

  • ohos.permission.APPROXIMATELY_LOCATION

  • ohos.permission.LOCATION_IN_BACKGROUND

If your application needs to access the device location information, it must first apply for required permissions. Specifically speaking:

API versions earlier than 9: Apply for ohos.permission.LOCATION.

API 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.

API VersionLocation PermissionPermission Application ResultLocation Accuracy
Earlier than 9ohos.permission.LOCATIONSuccessLocation accurate to meters
9 and laterohos.permission.LOCATIONFailureNo location obtained
9 and laterohos.permission.APPROXIMATELY_LOCATIONSuccessLocation accurate to 5 kilometers
9 and laterohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATIONSuccessLocation accurate to meters

If 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.

You can declare the required permission in your application's configuration file. For details, see the permission application guide.

Key API/Component Changes

Applications using API versions earlier than 9 are not affected.

If your application uses API version 9 or later and needs to call APIs requiring the ohos.permission.LOCATION permission in @ohos.geolocation and @ohos.geoLocationManager, you need to apply for the corresponding permission as described previously.

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Distributed Scheduler Subsystem ChangeLog

harmony 鸿蒙Wi-Fi Subsystem ChangeLog

harmony 鸿蒙Ability Subsystem ChangeLog

harmony 鸿蒙Account Subsystem ChangeLog

harmony 鸿蒙Customization Subsystem ChangeLog

harmony 鸿蒙Multimedia Subsystem ChangeLog

harmony 鸿蒙Common Event and Notification Subsystem ChangeLog

harmony 鸿蒙User IAM Subsystem ChangeLog

  • 所属分类: 后端技术
  • 本文标签: 软件 鸿蒙
  • 版权声明: 本文链接 https://seaxiang.com/blog/6fe316448dcd49ce90abbd96471ed4bf