Loading

NEO-7M定位信息转换

标准

一、 目前国内正在使用的有两种坐标系

  1. 火星坐标系 (GCJ-02)
  2. 百度坐标系 (BD-09)

二、 国内的地图软件获取的位置一般是自己的标准,例如百度的BD-09,各自之间不太通用。
三、 传感器获取的经纬度(例如GPS与北斗)是原始数据,也不能直接拿来在各大地图api上使用

转化为WGS84(全球通用GPS标准)

NEO-7M获取的经纬度信息是abcde.figh格式,这个理论精确度是0.1m,但是直接获取的地理位置信息不能直接用,需要先转化为标准的位置信息。计算方法是小数点前高位不足补零,小数点后位数不足补零按位计算abc+de/60+figh/600000或者是abc+de.figh/60
不考虑性能的java示例代码

    public static double NEO7MToWgs84(Stringneo7m) {
        String tempValue = neo7m;
        //将数据长度格式化为abcde.figh格式
        String[] valueTable = tempValue.split("\\.");
        while (valueTable[0].length() < 5 || valueTable[1].length() < 4) {
            if (valueTable[0].length() < 5) {
                valueTable[0] = "0" + valueTable[0];
            }
            if (valueTable[1].length() < 4) {
                valueTable[1] += "0";
            }
        }
        double abc = Double.parseDouble(valueTable[0].substring(0, 3));
        double de = Double.parseDouble(valueTable[0].substring(3, 5));
        double figh = Double.parseDouble(valueTable[1].substring(0, 4));
        return abc + de / 60 + figh / 600000;
    }

C++11版本

//实际使用需要添加正则表达式库,不要用以下include
#include <bits/stdc++.h>
using namespace std;
class Utils
{
public:
    /**
 * @brief Neo7m To Wgs84
 * 
 * @param neo7m Neo7m raw data
 * @return double Wgs84
 */
    static double Neo7mToWgs84(std::string neo7m)
    {
        if (neo7m.length() <= 2)
        {
            return 0.0;
        }
        //匹配数据为abcde.figh格式
        std::regex neo7reg("\\d+\\.\\d+");
        std::smatch neo7results;
        std::regex_search(neo7m, neo7results, neo7reg);
        std::string tempNeo7 = neo7results.str();
        std::string abcde = tempNeo7.substr(0, tempNeo7.find("."));
        while (abcde.length() < 5)
        {
            abcde.insert(abcde.begin(), '0');
        }
        std::string figh = tempNeo7.substr(tempNeo7.find(".") + 1);
        while (figh.length() < 4)
        {
            figh.insert(figh.begin(), '0');
        }
        return stod(abcde.substr(0, 3)) + stod(abcde.substr(3, 2)) / 60 + stod(figh.substr(0, 4)) / 600000;
    }
};

int main()
{
    std::cout << Utils::Neo7mToWgs84("11337.47512 E") << std::endl;
}

WGS84转其他参考https://blog.csdn.net/weixin_34356310/article/details/93012277

posted @ 2020-12-11 10:28  WindSnowLi  阅读(23)  评论(0编辑  收藏  举报