文档开发者中心
我的
|

HarmonyOS 5

【鸿蒙极客新势力申请】

#我要成为鸿蒙极客

在技术上分享了很多开源项目经验,在竞赛上参加了很多软件开发竞赛 ,鸿蒙创新赛,开放原子大赛

在参与鸿蒙应用激励计划中,我开发了宠悦通APP 下面说一下我的开发心得

在实现的鸿蒙开发能力中我使用了

  • ArkUI/ArkTS 声明式 UI:@Entry/@Component、@State、Column/Row/Scroll/Grid/ForEach

    • 可实现:高性能原生 UI、响应式渲染、资源化主题/尺寸/颜色

    • 定位能力:@ohos.geoLocationManager + ohos.permission.LOCATION/APPROXIMATELY_LOCATION

      • 用途:Hospitals.ets 获取当前经纬度,计算附近医院距离并排序。

        收起
        自动换行
        深色代码主题
        复制
             const dist = (aLat: number, aLon: number) => {
                const R = 6371; // km
                const dLat = (aLat - lat) * Math.PI / 180;
                const dLon = (aLon - lon) * Math.PI / 180;
                const h = Math.sin(dLat/2)**2 + Math.cos(lat*Math.PI/180)*Math.cos(aLat*Math.PI/180)*Math.sin(dLon/2)**2;
                return 2 * R * Math.asin(Math.sqrt(h));
              };
              this.places = hospitals
                .map((h: HospitalSeed) => ({ name: h.name, distanceKm: dist(h.lat, h.lon) } as HospitalPlace))
                .sort((a: HospitalPlace, b: HospitalPlace) => a.distanceKm - b.distanceKm);
            } catch (_e) {
              this.locationText = '无法获取定位,已显示推荐机构';
        收起
        自动换行
        深色代码主题
        复制
        private async fetchLocationAndList() {
            try {
              const location: geolocationManager.Location = await new Promise((resolve, reject) => {
                geolocationManager.getCurrentLocation((err: BusinessError, loc: geolocationManager.Location) => {
                  if (err) reject(err);
                  else resolve(loc);
                })
              });
              const lat: number = location.latitude;
              const lon: number = location.longitude;
              this.locationText = `当前位置:${lat.toFixed(4)}, ${lon.toFixed(4)}`;

        后续将会上架更多的鸿蒙原生app ,期待与鸿蒙开启新的篇章。

点赞
收藏
回复
分享
举报
浏览59 发布于2025-10-31 10:42湖北
全部评论
最多点赞
最新发布
最早发布
暂无评论
暂无评论
写回答
新增插入模板功能
一键使用模板,快速填写内容,轻松发帖~
知道了
  • 为了保障您的信息安全,请勿上传您的敏感个人信息(如您的密码等信息)和您的敏感资产信息(如关键源代码、签名私钥、调试安装包、业务日志等信息),且您需自行承担由此产生的信息泄露等安全风险。
  • 如您发布的内容为转载内容,请注明内容来源。

我要发帖子

了解社区公约,与您携手共创和谐专业的开发者社区。