【HarmonyOS】ArkTS如何打开高德地图导航功能

发布时间 2023-12-29 10:59:25作者: Mayism123
【关键字】

鸿蒙应用开发、ArkTS、拉起高德地图、打开导航

 

1、写在前面

在应用开发的过程中,可能会遇到过这样的需求,拉起第三方导航应用,比如点击某个按钮直接跳转到高德地图导航的页面,那这个需求在鸿蒙中该如何实现呢?

 

2、解决方案

对于这个需求,其实实现起来也很简单,通过deeplink的方式,在ArkTS中通过startAbility来拉起应用。

首先我们先找到高德地图导航的开发指南:

https://lbs.amap.com/api/amap-mobile/guide/android/navigation

核心点就是这个链接:

cke_331.png

然后来写一个跳转到高德地图导航页面的方法:

jumpGaode() {
    let context = getContext(this) as common.UIAbilityContext
    context.startAbility({
      uri: "androidamap://navi?sourceApplication=appname&lat=" + this.latitude + "&lon=" + this.longitude + "&dev=1",
      action: "android.intent.action.VIEW"
    })
  }

接着在页面中进行测试:

Button('打开高德地图')
        .onClick(() => {
          this.jumpGaode()
        })
        .margin({ top: 50 })
        .width(200).height(45)

完整代码如下:

cke_4580.png​​

最后来看一下实现的效果: