找回密码
 立即注册

微信扫码登录

搜索
楼主: left

[技术讨论] 安装墨澜地图增强版之后,汽车定位依旧偏移

[复制链接]

51

主题

344

回帖

2814

积分

金牌会员

积分
2814
金钱
2419
HASS币
0
发表于 2024-6-1 10:39:43 | 显示全部楼层
dscao 发表于 2024-5-31 20:59
bg6rsh/traccar-amap:5.8 是适配过国内坐标的,默认的国内坐标的高德地图就刚好。
问题可能就出在这了,用 ...

目前这一套的坐标是没问题的,在HA和自建的traccar 都没问题

但是使用墨澜地图以后,ha_traccar的设备在 墨澜地图上存在地址偏移

需要修改源码来调整墨澜地图的坐标系吗?
回复

使用道具 举报

left 手机认证

1

主题

16

回帖

101

积分

注册会员

积分
101
金钱
84
HASS币
0
 楼主| 发表于 2025-1-19 19:28:08 | 显示全部楼层
更新!现在不偏移了!小白靠着大佬的代码和AI更改了一下device_tracker.py的代码
主要改动就是引入一个数学函数,然后设置无论什么条件都用这个函数修改坐标
代码如下



import math

class MercedesMEDeviceTracker(MercedesMeEntity, TrackerEntity, RestoreEntity):
    """Representation of a Sensor."""
 
    # 假设 GCJ2WGS 函数是一个静态方法或者是一个独立的工具函数
    @staticmethod
    def GCJ2WGS(lon, lat):
        a = 6378245.0  # 克拉索夫斯基椭球参数长半轴a
        ee = 0.00669342162296594323  # 克拉索夫斯基椭球参数第一偏心率平方
        PI = 3.14159265358979324  # 圆周率
 
        x = lon - 105.0
        y = lat - 35.0
 
        dLon = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * math.sqrt(abs(x))
        dLon += (20.0 * math.sin(6.0 * x * PI) + 20.0 * math.sin(2.0 * x * PI)) * 2.0 / 3.0
        dLon += (20.0 * math.sin(x * PI) + 40.0 * math.sin(x / 3.0 * PI)) * 2.0 / 3.0
        dLon += (150.0 * math.sin(x / 12.0 * PI) + 300.0 * math.sin(x / 30.0 * PI)) * 2.0 / 3.0
 
        dLat = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * math.sqrt(abs(x))
        dLat += (20.0 * math.sin(6.0 * x * PI) + 20.0 * math.sin(2.0 * x * PI)) * 2.0 / 3.0
        dLat += (20.0 * math.sin(y * PI) + 40.0 * math.sin(y / 3.0 * PI)) * 2.0 / 3.0
        dLat += (160.0 * math.sin(y / 12.0 * PI) + 320 * math.sin(y * PI / 30.0)) * 2.0 / 3.0
        radLat = lat / 180.0 * PI
        magic = math.sin(radLat)
        magic = 1 - ee * magic * magic
        sqrtMagic = math.sqrt(magic)
        dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI)
        dLon = (dLon * 180.0) / (a / sqrtMagic * math.cos(radLat) * PI)
        wgsLon = lon - dLon
        wgsLat = lat - dLat
        return [wgsLat, wgsLon]

    @property
    def latitude(self) -> float | None:
        """Return latitude value of the device, converted to WGS-84 if necessary."""
        lat = self._get_car_value("location", "positionLat", "value", 0)
        lng = self._get_car_value("location", "positionLong", "value", 0)
 
        if lat is not None and lng is not None:
            wgs_lat, _ = self.GCJ2WGS(lng, lat)  # 注意:经度和纬度的顺序
            return wgs_lat
        return lat
 
    @property
    def longitude(self) -> float | None:
        """Return longitude value of the device, converted to WGS-84 if necessary."""
        lat = self._get_car_value("location", "positionLat", "value", 0)
        lng = self._get_car_value("location", "positionLong", "value", 0)
 
        if lat is not None and lng is not None:
            _, wgs_lng = self.GCJ2WGS(lng, lat)  # 注意:经度和纬度的顺序
            return wgs_lng
        return lng
 
    @property
    def source_type(self):
        """Return the source type, eg gps or router, of the device."""
        return SourceType.GPS  # 假设 SourceType 是一个已经定义的枚举或常量
 
    @property
    def device_class(self):
        """Return the device class of the device tracker."""
        return None
回复

使用道具 举报

15

主题

533

回帖

3029

积分

论坛元老

积分
3029
金钱
2481
HASS币
0
发表于 2025-6-10 20:45:19 | 显示全部楼层
left 发表于 2025-1-19 19:28
更新!现在不偏移了!小白靠着大佬的代码和AI更改了一下device_tracker.py的代码
主要改动就是引入一个数学 ...

这是修改哪里的device_tracker.py,我也是用坛里修改版的tracaar,然后墨澜地图有偏移
回复

使用道具 举报

left 手机认证

1

主题

16

回帖

101

积分

注册会员

积分
101
金钱
84
HASS币
0
 楼主| 发表于 2025-7-29 10:03:14 | 显示全部楼层
jjss520 发表于 2025-6-10 20:45
这是修改哪里的device_tracker.py,我也是用坛里修改版的tracaar,然后墨澜地图有偏移 ...

修改汽车的,我是改了梅赛德斯的
回复

使用道具 举报

0

主题

24

回帖

59

积分

注册会员

积分
59
金钱
35
HASS币
0
发表于 2025-9-18 10:36:07 | 显示全部楼层
看这种帖子能学到很多东西
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Hassbian ( 晋ICP备17001384号-1 )

GMT+8, 2025-10-3 14:30 , Processed in 0.087719 second(s), 8 queries , MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表