写点什么

【HarmonyOS】鸿蒙应用实现调用系统地图导航或路径规划

作者:GeorgeGcs
  • 2025-06-25
    上海
  • 本文字数:1046 字

    阅读完需:约 3 分钟

##鸿蒙开发能力 ##HarmonyOS SDK 应用服务 ##鸿蒙金融类应用 (金融理财 #

前言

在涉及地图业务中,调用地图导航和路径规划是三方应用中较为常见的功能。


若只是子业务需要地图导航效果,整个 APP 内部集成地图去实现导航或者路径规划,会造成 SDK 集成冗余。毕竟很重。


所以该效果一般会调用系统地图,来显示当前坐标和目标坐标的路径规划或者实时导航。


鸿蒙系统提供了一种极其简单的调用方式,默认是自己当前的坐标为基础,


需要注意的是,国内的坐标系是 GCJ02 坐标系,国外才是 wgs84 坐标系。

示例效果

地图导航:



路径规划:


DEMO 示例

系统地图应用的包名为:'com.huawei.hmos.maps.app'


import { common, Want } from '@kit.AbilityKit';
@Entry@Componentstruct Index {

aboutToAppear(): void {
}
StartNavi = ()=>{ let petalMapWant: Want = { bundleName: 'com.huawei.hmos.maps.app', uri: 'maps://routes', // 路径规划 // uri: 'maps://navigation', // 导航 parameters: { // 接入方业务名或包名,Link请求来源。 linkSource: 'com.example.navitest', destinationLatitude: 40.0382556, destinationLongitude: 116.3144536, // 终点Poi ID,如果有,优先使用(Map Kit返回的Poi信息含Poi ID)。 destinationPoiId: '906277887815706098', destinationName: '北京清河高铁站', vehicleType: 0 // 交通出行工具。0-驾车, 1-步行, 2-骑行。默认驾车 } }
let context = getContext(this) as common.UIAbilityContext; context.startAbility(petalMapWant); }
build() { RelativeContainer() { Text("唤起导航") .id('HelloWorld') .fontSize(50) .fontWeight(FontWeight.Bold) .alignRules({ center: { anchor: '__container__', align: VerticalAlign.Center }, middle: { anchor: '__container__', align: HorizontalAlign.Center } }) .onClick(this.StartNavi) } .height('100%') .width('100%') }}
复制代码


wgs84 坐标系转化为 gcj02:


import { map, mapCommon } from '@kit.MapKit';
let wgs84Position: mapCommon.LatLng = { latitude: 30, longitude: 118};let gcj02Position: mapCommon.LatLng = map.convertCoordinateSync(mapCommon.CoordinateType.WGS84, mapCommon.CoordinateType.GCJ02, wgs84Position);
复制代码


用户头像

GeorgeGcs

关注

路漫漫其修远兮,吾将上下而求索。 2024-12-24 加入

鸿蒙创作先锋,华为HDE专家,鸿蒙讲师,作者。 目前任职鸿蒙应用架构师。历经腾讯,宝马,研究所,金融。 待过私企,外企,央企。 深耕大应用开发领域十年。 OpenHarmony,HarmonyOS,Flutter,H5,Android,IOS。

评论

发布
暂无评论
【HarmonyOS】鸿蒙应用实现调用系统地图导航或路径规划_GeorgeGcs_InfoQ写作社区