• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Location Subsystem Changelog
2
3## cl.location.1 Migration of System APIs and APIs in API Version 9 to the New @ohos.geoLocationManager.d.ts
4
5The APIs in **@ohos.geolocation.d.ts** do not support throwing error codes. However, APIs in API version 9 and system APIs are required to support throwing of 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.
6
7To use system APIs and APIs in API version 9 of the location subsystem, you need to import **@ohos.geoLocationManager**.
8
9import geoLocationManager from '@ohos.geoLocationManager';
10
11
12**Change Impact**
13
14System APIs and APIs in API version 9 are affected. To ensure normal use of these APIs, you need to import **@ohos.geoLocationManager**.
15
16import geoLocationManager from '@ohos.geoLocationManager';
17
18Other APIs are not affected.
19
20**Key API/Component Changes**
21
22| Class| API Type| Declaration| Change Type|
23|  -- | -- | -- | -- |
24|geolocation| namespace | declare namespacegeolocation| Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
25|geolocation | interface | export interface ReverseGeocodingMockInfo  | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
26|geolocation | interface | export interface LocationMockConfig  | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
27|geolocation | interface | export interface CountryCode   | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
28|geolocation | enum | export enum CountryCodeType   | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
29|geolocation.GeoAddress | field | isFromMock?: Boolean; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
30|geolocation.Location  | field | isFromMock?: Boolean; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
31|geolocation.GeoLocationErrorCode  | field | NOT_SUPPORTED = 100 | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
32|geolocation.GeoLocationErrorCode  | field | QUERY_COUNTRY_CODE_ERROR | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
33|geolocation| method | function on(type: 'countryCodeChange', callback: Callback<CountryCode>): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
34|geolocation| method | function off(type: 'countryCodeChange', callback?: Callback<CountryCode>): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
35|geolocation| method | function getCountryCode(callback: AsyncCallback<CountryCode>): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
36|geolocation| method | function getCountryCode(): Promise<CountryCode>; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
37|geolocation| method | function enableLocationMock(scenario: LocationRequestScenario, callback: AsyncCallback<void>): void; | Deleted this API in API version 9.|
38|geolocation| method | function enableLocationMock(callback: AsyncCallback<void>): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
39|geolocation| method | function enableLocationMock(scenario: LocationRequestScenario): Promise<void>; | Deleted this API in API version 9.|
40|geolocation| method | function enableLocationMock(): Promise<void>; |  Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**.|
41|geolocation| method | function disableLocationMock(scenario: LocationRequestScenario, callback: AsyncCallback<void>): void; | Deleted this API in API version 9.|
42|geolocation| method | function disableLocationMock(callback: AsyncCallback<void>): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
43|geolocation| method | function disableLocationMock(scenario: LocationRequestScenario): Promise<void>; | Deleted this API in API version 9.|
44|geolocation| method | function disableLocationMock(): Promise<void>; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
45|geolocation| method | function setMockedLocations(config: LocationMockConfig, callback: AsyncCallback<void>): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
46|geolocation| method | function setMockedLocations(config: LocationMockConfig): Promise<void>; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
47|geolocation| method | function enableReverseGeocodingMock(callback: AsyncCallback<void>): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
48|geolocation| method | function enableReverseGeocodingMock(): Promise<void>; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
49|geolocation| method | function disableReverseGeocodingMock(callback: AsyncCallback<void>): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
50|geolocation| method | function disableReverseGeocodingMock(): Promise<void>; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
51|geolocation| method | function setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>, callback: AsyncCallback<void>): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
52|geolocation| method | function setReverseGeocodingMockInfo(mockInfos: Array<ReverseGeocodingMockInfo>): Promise<void>; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
53|geolocation| method | function isLocationPrivacyConfirmed(type: LocationPrivacyType, callback: AsyncCallback<boolean>): void; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
54|geolocation| method | function isLocationPrivacyConfirmed(type: LocationPrivacyType): Promise<boolean>; | Migrated this API in API version 9 to **@ohos.geoLocationManager.d.ts**. |
55|geolocation| method | function 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**. |
56|geolocation| method | function 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**. |
57
58**(Optional) Adaptation Guide**
59
60The following sample code shows how to call **enableLocation** in the new version:
61
62  ```ts
63  import geoLocationManager from '@ohos.geoLocationManager';
64  try {
65      geoLocationManager.enableLocation((err, data) => {
66          if (err) {
67              console.log('enableLocation: err=' + JSON.stringify(err));
68          }
69      });
70  } catch (err) {
71      console.error("errCode:" + err.code + ",errMessage:" + err.message);
72  }
73  ```
74
75## cl.location.2 Location Service Permission Change
76
77From API version 9, the **ohos.permission.APPROXIMATELY_LOCATION** permission is added for obtaining the approximate location.
78
79If 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.
80
81**Change Impact**
82
83Applications 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:
84
85Before 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.
86
87The system provides the following location permissions:
88
89- ohos.permission.LOCATION
90
91- ohos.permission.APPROXIMATELY_LOCATION
92
93- ohos.permission.LOCATION_IN_BACKGROUND
94
95If your application needs to access the device location information, it must first apply for required permissions. Specifically speaking:
96
97API versions earlier than 9: Apply for **ohos.permission.LOCATION**.
98
99API 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.
100
101| API Version| Location Permission| Permission Application Result| Location Accuracy|
102| -------- | -------- | -------- | -------- |
103| Earlier than 9| ohos.permission.LOCATION | Success| Location accurate to meters|
104| 9 and later| ohos.permission.LOCATION | Failed| No location obtained.|
105| 9 and later| ohos.permission.APPROXIMATELY_LOCATION | Success| Location accurate to 5 kilometers.|
106| 9 and later| ohos.permission.APPROXIMATELY_LOCATION and ohos.permission.LOCATION| Success| Location accurate to meters|
107
108If 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.
109
110You can declare the required permissions in your application's configuration file. For details, see the [permission application guide](../../../application-dev/security/accesstoken-guidelines.md).
111
112**Key API/Component Changes**
113
114Applications using API versions earlier than 9 are not affected.
115
116If 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.
117