HarmonyOS 调用getCurrentLocation,获取经纬度

我通过调用getCurrentLocation,获取经纬度,定位比实际位置偏移很多,请问调用getCurrentLocation获取经纬度属于哪个坐标系呢?

我测试的结果getCurrentLocation获取经纬度应该为WGS84,然后通过转换为GCJ02就差不多了,然后想确认一下

HarmonyOS
2025-01-10 08:47:20
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
zxjiu

这样处理是没问题的。

当前LocationKit提供的默认坐标系都是84坐标系,地图的地理坐标在国内站点使用时,需要先将其转换为GCJ02坐标系再访问。这是因为华为地图涉及到的坐标系知识介绍中指出,在国内(包括港澳)通过WGS84坐标调用Map Kit服务时需要进行坐标转换。如果不进行转换,可能会导致展示位置有偏移。

以下是文档中的示例代码:

我的位置:

// 需要引入@ohos.geoLocationManager模块
import { geoLocationManager } from '@kit.LocationKit';
// ...

// 获取用户位置坐标
let location = await geoLocationManager.getCurrentLocation();

// 设置用户的位置
let position = await geoLocationManager.getCurrentLocation();
this.mapController.setMyLocation(position);

地图坐标系说明及转换:

import { map, mapCommon } from '@kit.MapKit';

let wgs84Position: mapCommon.LatLng = {
  latitude: 30,
  longitude: 118
};
let gcj02Position: mapCommon.LatLng = await map.convertCoordinate(mapCommon.CoordinateType.WGS84, mapCommon.CoordinateType.GCJ02,wgs84Position);

参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/map-convert-coordinate-V5

分享
微博
QQ
微信
回复
2025-01-10 10:14:03
相关问题
如何获取经纬度示例代码
1418浏览 • 1回复 待解决
HarmonyOS 坐标系经纬度转换
695浏览 • 1回复 待解决
HarmonyOS 有关经纬度问题
428浏览 • 1回复 待解决
HarmonyOS map kit 获取地图中心经纬度
576浏览 • 1回复 待解决
HarmonyOS 获取经纬的案例
370浏览 • 1回复 待解决