zoukankan      html  css  js  c++  java
  • 根据坐标算距离,并排序

    //算距离
        public static double getDistance(double lng1,double lat1,double lng2,double lat2){
            double radLat1 = Math.toRadians(lat1);
            double radLat2 = Math.toRadians(lat2);
            double a = radLat1 - radLat2;
            double b = Math.toRadians(lng1) - Math.toRadians(lng2);
            double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLat1)
                    * Math.cos(radLat2) * Math.pow(Math.sin(b / 2), 2)));
            s = s * 6378137.0;// 取WGS84标准参考椭球中的地球长半径(单位:m)
            s = Math.round(s * 10000) / 10000;
            s = s/1000;
            return s;
        }

     排序:

    //算距离
    double latitude=Double.parseDouble(dto.getLatitude());//纬度
    double longitude = Double.parseDouble(dto.getLongitude());//经度 distance = getDistance(longitude,latitude,Double.parseDouble(dataLongitude),Double.parseDouble(dataLatitude)); //查出所有距离,封装map //list1 为for循环每次查询出的数聚距离集合,初始值为null
    Map<String,String> map = new HashMap<String, String>(); map.put("index", i+""); map.put("distance", distance+""); list1.add(map); //距离排序 Collections.sort(list1, new Comparator() { public int compare(Object a, Object b) { double one = Double.parseDouble(((Map<String,String>)a).get("distance")); double two = Double.parseDouble(((Map<String,String>)b).get("distance")); return (int) (one - two); } //排完距离的顺序,从新赋值index List<InterNodeInfoDto> list2 = new ArrayList<InterNodeInfoDto>(); for(Map<String,String> temp : list1){ list2.add(list.get(Integer.parseInt(temp.get("index")))); }
  • 相关阅读:
    postman批量运行和参数化
    Loadrunner 参数化数据分配方法以及数据更新方式
    常用函数
    获取 layer.msg 弹窗的信息
    登录页脚本小结
    关于linux下system()函数的总结
    请不要重复犯我在学习Python和Linux系统上的错误
    教你摸清 Linux PC 的性能底细?
    Ubuntu GNOME 16.10 Beta 1问世了!
    Google疯了,竟然这样!
  • 原文地址:https://www.cnblogs.com/Linger-wj/p/6728573.html
Copyright © 2011-2022 走看看