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