HarmonyOS鸿蒙Next中应用如何跳转至系统的地图软件中并进行导航

HarmonyOS鸿蒙Next中应用如何跳转至系统的地图软件中并进行导航 应用如何跳转至系统的地图软件中并进行导航
应用如何跳转至系统的地图软件中并进行导航
按照文档中的方式无法正常跳转至导航界面

let petalMapWant: Want = {
  bundleName: 'com.huawei.hmos.maps.app',
  uri: 'maps://navigation',
  parameters: {
    linkSource: 'com.other.app',
    destinationLatitude: 40.0382556,
    destinationLongitude: 116.3144536,
    destinationPoiId: '906277887815706098',
    destinationName: '清河火车站',
    vehicleType: 0
  }
}
context.startAbility(petalMapWant)

更多关于HarmonyOS鸿蒙Next中应用如何跳转至系统的地图软件中并进行导航的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

先检查一下want的参数是不是对的,为了方便定位,请提供下【按照文档中的方式无法正常跳转至导航界面】你看的这个文档的地址。

该功能在3.0.0.22上才能使用,版本链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-releases-V5/releasenotes-overview-V5#section956319204246

更多关于HarmonyOS鸿蒙Next中应用如何跳转至系统的地图软件中并进行导航的实战系列教程也可以访问 https://www.itying.com/category-93-b0.html


在HarmonyOS鸿蒙Next中,应用可以通过调用系统的地图软件进行导航。具体步骤如下:

  1. 导入相关依赖:首先,在应用的build.gradle文件中添加对@ohos.geolocation@ohos.intent的依赖。

  2. 获取当前位置:使用geolocation模块获取用户的当前位置信息。可以通过getCurrentLocation方法获取经纬度坐标。

  3. 构建Intent对象:创建一个Intent对象,设置actionACTION_VIEW,并将uri设置为地图导航的URI格式。例如,geo:latitude,longitude?q=destination_name

  4. 启动地图应用:调用startAbility方法,将Intent对象传递给系统,系统会自动启动地图应用并进行导航。

import geolocation from '@ohos.geolocation';
import featureAbility from '@ohos.ability.featureAbility';

// 获取当前位置
geolocation.getCurrentLocation((err, location) => {
    if (err) {
        console.error('获取位置失败', err);
        return;
    }

    const latitude = location.latitude;
    const longitude = location.longitude;

    // 构建Intent对象
    const intent = {
        action: 'ohos.intent.action.VIEW',
        uri: `geo:${latitude},${longitude}?q=目的地`
    };

    // 启动地图应用
    featureAbility.startAbility(intent).then(() => {
        console.log('地图应用启动成功');
    }).catch((error) => {
        console.error('地图应用启动失败', error);
    });
});

通过以上步骤,应用可以跳转至系统的地图软件并进行导航。

在HarmonyOS鸿蒙Next中,应用可以通过Intent跳转至系统的地图软件并启动导航。首先,构造一个包含目的地经纬度和导航模式的Intent对象,然后调用startAbility方法启动地图应用。例如:

Intent intent = new Intent();
Operation operation = new Intent.OperationBuilder()
    .withAction("android.intent.action.VIEW")
    .withUri("geo:39.9042,116.4074?q=目的地名称")
    .build();
intent.setOperation(operation);
startAbility(intent);

其中,geo:39.9042,116.4074表示目的地的经纬度,q=目的地名称为可选的地址名称。

回到顶部