# location **Repository Path**: harmony-free/location ## Basic Information - **Project Name**: location - **Description**: Harmony OS location 鸿蒙位置定位库 - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-05-23 - **Last Updated**: 2025-07-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # location #### Description [中文](README.md) Harmony OS location plugin。Current location information、Current "GCJ02" location information、Obtain positioning、 Obtain nearby location information、Obtain nearby positioning based on latitude and longitude、 Get nearby location based on the address、Obtain nearby location based on address or latitude/longitude coordinates、Transform GCJ02 positioning #### Software Architecture Based on the system's positioning request library, the "Location" module is encapsulated. #### Installation `ohpm install @free/location` #### Instruction Manual 1、Initialization ``` local:Location = new Location() /** * Current location information * @returns geoLocationManager.Location */ this.local.currentLocation() /** * Current "GCJ02" location information * @returns geoLocationManager.Location */ this.local.currentLocationGCJ02() /** * Obtain positioning * @returns geoLocationManager.GeoAddress */ this.local.location() /** * Obtain nearby location information * @returns Array */ this.local.locationList() /** * Obtain nearby positioning based on latitude and longitude * @returns Array */ this.local.locationAddress() /** * Get nearby location based on the address * description:string * @returns Array */ this.local.locationAddressName() /** * Obtain nearby location based on address or latitude/longitude coordinates * @returns Array */ this.local.locationAddressList() /** * Transform GCJ02 positioning * @returns mapCommon.LatLng */ toGCJ02(latLong:mapCommon.LatLng) ``` #### Plugin Details Hello, dear students! Good morning! Today, we are going to talk about the commonly used positioning function in HONAM. In the process of developing maps, nearby people, delivery addresses, nearby shopping malls and other functions, the positioning function is basically used. Positioning is closely related to life. Different countries use different positioning calculation methods, and the positioning of different apps is also different. 1. Obtain the location based on the address name or latitude/longitude, or obtain nearby locations. ``` /** * 获取定位 * @returns geoLocationManager.GeoAddress */ async location(data?:string|mapCommon.LatLng|undefined): Promise { return new Promise((res, rej) => { try { if (data == undefined) { this.currentLocation().then((location)=>{ this.locationAddress({latitude:location.latitude,longitude:location.longitude}).then((list)=>{ if (list.length > 0) { res(list[0]); }else{ console.error("errCode:" + "500" + ", message:" + "数据为空"); rej("errCode:" + "500" + ", message:" + "数据为空"); } }) }) }else { this.locationAddressList(data).then((list)=>{ if (list.length > 0) { res(list[0]); }else{ console.error("errCode:" + "500" + ", message:" + "数据为空"); rej("errCode:" + "500" + ", message:" + "数据为空"); } }) } } catch (err) { console.error("errCode:" + err.code + ", message:" + err.message); rej(err) } }) } ``` 2. Position conversion: WGS84 to GCJ02 positioning and GCJ02 to WGS84 conversion ``` toGCJ02(latLong:mapCommon.LatLng):mapCommon.LatLng{ return map.convertCoordinateSync(mapCommon.CoordinateType.WGS84, mapCommon.CoordinateType.GCJ02, latLong); } toWGS84(latLong:mapCommon.LatLng):mapCommon.LatLng{ return map.convertCoordinateSync(mapCommon.CoordinateType.GCJ02, mapCommon.CoordinateType.WGS84, latLong); } ``` Note: The complete code has been submitted to the [HarmonyOS Third-Party Library](https://ohpm.openharmony.cn/). Please use the following command to install it. If you like this content, please give a little heart! #### Contribution 1. Fork the repository 2. Create Feat_xxx branch 3. Commit your code 4. Create Pull Request #### Gitee Feature 1. You can use Readme\_XXX.md to support different languages, such as Readme\_en.md, Readme\_zh.md 2. Gitee blog [blog.gitee.com](https://blog.gitee.com) 3. Explore open source project [https://gitee.com/explore](https://gitee.com/explore) 4. The most valuable open source project [GVP](https://gitee.com/gvp) 5. The manual of Gitee [https://gitee.com/help](https://gitee.com/help) 6. The most popular members [https://gitee.com/gitee-stars/](https://gitee.com/gitee-stars/)