鸿蒙app 开发中如何计算两个点 之间的距离
官方有提供的方法 通过 两个点 的坐标 计算 两个 点之间的距离
记得获取先当前的定位
官方文档
具体的实现方式
开发步骤
- 导入相关模块。
- import { map, mapCommon } from '@kit.MapKit';
- 初始化需要计算的坐标,调用calculateDistance方法计算距离。
- let fromLatLng: mapCommon.LatLng = {
- latitude: 38,
- longitude: 118
- };
- let toLatLng: mapCommon.LatLng = {
- latitude: 39,
- longitude: 119
- };
- let distance = map.calculateDistance(fromLatLng, toLatLng);