1# Geocoding and Reverse Geocoding 2 3## Scenario 4 5Describing a location using coordinates is accurate, but neither intuitive nor user-friendly. To address this issue, the system provides your application the geocoding and reverse geocoding capabilities: 6 7- Geocoding: converts geographic descriptions into specific coordinates. 8 9- Reverse geocoding: converts coordinates into geographic descriptions. 10 11The geocoding information describes a location using several attributes, including the country, administrative region, street, house number, and address, etc. 12 13## Available APIs 14 15The following table lists the APIs used for mutual conversion between coordinates and geographic descriptions. For details, see [Location Kit](../../reference/apis-location-kit/js-apis-geoLocationManager.md). 16 17**Table 3** Geocoding and reverse geocoding APIs 18 19| API| Description| 20| -------- | -------- | 21| [isGeocoderAvailable(): boolean;](../../reference/apis-location-kit/js-apis-geoLocationManager.md#geolocationmanagerisgeocoderavailable) | Checks whether the geocoding and reverse geocoding services are available.| 22| [getAddressesFromLocation(request: ReverseGeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void](../../reference/apis-location-kit/js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocation) | Converts coordinates into geographic descriptions through reverse geocoding. This API uses an asynchronous callback to return the result. | 23| [getAddressesFromLocationName(request: GeoCodeRequest, callback: AsyncCallback<Array<GeoAddress>>): void](../../reference/apis-location-kit/js-apis-geoLocationManager.md#geolocationmanagergetaddressesfromlocationname) | Converts geographic descriptions into coordinates through geocoding. This API uses an asynchronous callback to return the result. | 24 25## How to Develop 26 27> **NOTE** 28> The geocoding and reverse geocoding services need to access backend services to obtain information. Therefore, before performing the following steps, ensure that your device is connected to the network. 29 301. Import the **geoLocationManager** modules. All geocoding and reverse geocoding APIs are provided by this module. 31 32 ```ts 33 import { geoLocationManager } from '@kit.LocationKit'; 34 ``` 35 362. Check whether the geocoding and reverse geocoding services are available. 37 - Call **isGeoServiceAvailable** to check whether the geocoding and reverse geocoding services are available. If yes, go to step 3. If the services are unavailable, the device does not have the geocoding and reverse geocoding capabilities. Do not use related APIs. 38 39 ```ts 40 import { geoLocationManager } from '@kit.LocationKit'; 41 try { 42 let isAvailable = geoLocationManager.isGeocoderAvailable(); 43 } catch (err) { 44 console.error("errCode:" + JSON.stringify(err)); 45 } 46 ``` 47 483. Obtain the geocoding conversion result. 49 - Call **getAddressesFromLocation** to convert coordinates into geographical location information. Your application can obtain the list of [GeoAddress](../../reference/apis-location-kit/js-apis-geoLocationManager.md#geoaddress) objects that match the specified coordinates and then read location information from it. 50 51 ```ts 52 let reverseGeocodeRequest:geoLocationManager.ReverseGeoCodeRequest = {"latitude": 31.12, "longitude": 121.11, "maxItems": 1}; 53 try { 54 geoLocationManager.getAddressesFromLocation(reverseGeocodeRequest, (err, data) => { 55 if (err) { 56 console.log('getAddressesFromLocation err: ' + JSON.stringify(err)); 57 } else { 58 console.log('getAddressesFromLocation data: ' + JSON.stringify(data)); 59 } 60 }); 61 } catch (err) { 62 console.error("errCode:" + JSON.stringify(err)); 63 } 64 ``` 65 66 - Call **getAddressesFromLocationName** to convert the location description into coordinates. 67 68 ```ts 69 let geocodeRequest:geoLocationManager.GeoCodeRequest = {"description": "No. xx, xx Road, Pudong District, Shanghai", "maxItems": 1}; 70 try { 71 geoLocationManager.getAddressesFromLocationName(geocodeRequest, (err, data) => { 72 if (err) { 73 console.log('getAddressesFromLocationName err: ' + JSON.stringify(err)); 74 } else { 75 console.log('getAddressesFromLocationName data: ' + JSON.stringify(data)); 76 } 77 }); 78 } catch (err) { 79 console.error("errCode:" + JSON.stringify(err)); 80 } 81 ``` 82 83 Your application can obtain the list of [GeoAddress](../../reference/apis-location-kit/js-apis-geoLocationManager.md#geoaddress) objects that match the specified location description and then read coordinates from it. 84 85 If the location description contains duplicate location names, you can call [GeoCodeRequest](../../reference/apis-location-kit/js-apis-geoLocationManager.md#geocoderequest) to specify a longitude and latitude range to narrow down the scope. 86