redis中的geo功能能否直接使用高德地图gcj02的坐标?

可以在Redis GEO函数中直接使用高德坐标,即GCJ-02坐标。


测试

  1. 我们使用redis geo添加13个坐标。即:
        addGym("pku", 116.310845, 39.992912);//北大
        addGym("tingshua", 116.326724, 40.0033);//清华
        addGym("linda", 116.347495, 40.005602);//凌达
        addGym("nongda", 116.357366, 40.004813);//农大
        addGym("yuyanda", 116.346551, 39.995016);//语言大
        addGym("dida", 116.348954, 39.991465);//地大
        addGym("keda", 116.359254, 39.99015);//北科大
        addGym("beihang", 116.34698, 39.981666);//北航
        addGym("renda", 116.312991, 39.970485);//人大
        addGym("beishi", 116.365863, 39.961538);//北师
        addGym("beili", 116.314965, 39.959894);//北理
        addGym("minda", 116.32063, 39.950354);//民大
        addGym("beijiao", 116.342345, 39.952064);//北京交大
  1. 我们使用georadius功能以北京大学坐标为例进行测试
    #####距离为3公里,返回:

    {"id":"pku","latitude":39.99291283048765,"longitude":116.31084233522415}
    {"id":"tingshua","latitude":40.003300117798624,"longitude":116.32672637701035}
    {"id":"renda","latitude":39.970485617669816,"longitude":116.3129934668541}

    #####距离为5公里,返回:

    {"id":"beili","latitude":39.95989301794494,"longitude":116.31496757268906}
    {"id":"renda","latitude":39.970485617669816,"longitude":116.3129934668541}
    {"id":"beihang","latitude":39.98166627270366,"longitude":116.34698241949081}
    {"id":"dida","latitude":39.991465504705666,"longitude":116.34895652532578}
    {"id":"keda","latitude":39.99014998442397,"longitude":116.35925620794296}
    {"id":"pku","latitude":39.99291283048765,"longitude":116.31084233522415}
    {"id":"tingshua","latitude":40.003300117798624,"longitude":116.32672637701035}
    {"id":"yuyanda","latitude":39.995016649049894,"longitude":116.34655326604843}
    {"id":"linda","latitude":40.005601644611296,"longitude":116.34749740362167}
    {"id":"nongda","latitude":40.00481334633074,"longitude":116.35736793279648}
    {"id":"minda","latitude":39.95035486222235,"longitude":116.32063239812851}

这些测试结果都是正确的

  1. 我们对使用高德地图坐标的两个点间的距离进行测试
两点 使用redis geo测试的距离(高德坐标体系)/米 使用高德地图中测距工具实际测出的距离/公里
北大清华 1779.4863 1.8
北大人大 2501.224 2.5
北大北航 3324.2053 3.3
北大农大 4179.3899 4.1

结论

  1. redis geo使用高德坐标测试附近的距离正确。
  2. redis geo使用高德坐标,计算两点间距离正确。
因此可以认为高德地图坐标可以在redis geo中使用

(转自 https://wuwawuwa.cn )

你可能感兴趣的:(其他)