From 357c72932115936e91bfdc234b8dda468c575241 Mon Sep 17 00:00:00 2001
From: jinpengyong <jpy123456>
Date: Tue, 01 Aug 2023 09:11:20 +0800
Subject: [PATCH] chore:测试提交修改无人机接口

---
 screen-api/src/main/java/com/moral/api/service/UAVService.java          |   13 
 screen-api/src/main/java/com/moral/api/service/impl/UAVServiceImpl.java |  509 ++++++++++++++++++++++++++
 screen-api/src/main/java/com/moral/api/controller/UAVController.java    |  618 --------------------------------
 3 files changed, 529 insertions(+), 611 deletions(-)

diff --git a/screen-api/src/main/java/com/moral/api/controller/UAVController.java b/screen-api/src/main/java/com/moral/api/controller/UAVController.java
index 1e969e9..2323049 100644
--- a/screen-api/src/main/java/com/moral/api/controller/UAVController.java
+++ b/screen-api/src/main/java/com/moral/api/controller/UAVController.java
@@ -18,6 +18,7 @@
 import com.moral.api.pojo.vo.uav.UAVQueryTimeSlotVO;
 import com.moral.api.pojo.vo.uav.UAVQueryTimeSlotVOs;
 import com.moral.api.service.HistorySecondUavService;
+import com.moral.api.service.UAVService;
 import com.moral.constant.ResponseCodeEnum;
 import com.moral.constant.ResultMessage;
 import com.moral.util.DateUtils;
@@ -55,6 +56,8 @@
     HistorySecondUavService historySecondUavService;
     @Autowired
     HistorySecondUavMapper historySecondUavMapper;
+    @Autowired
+    UAVService uavService;
 
     /**
     * @Description: ������������������������������������������
@@ -75,279 +78,16 @@
         return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),vo);
     }
 
-    @PostMapping("test")
+    @PostMapping("getUav")
     public ResultMessage test(@RequestBody Map<String, Object> params){
         //������������������������
         if (!params.containsKey("mac") || !params.containsKey("batch") || !params.containsKey("height1")|| !params.containsKey("uvasize")|| !params.containsKey("height2")) {
             return ResultMessage.fail(ResponseCodeEnum.PARAMETERS_IS_MISSING.getCode(), ResponseCodeEnum.PARAMETERS_IS_MISSING.getMsg());
         }
-        String uvasize = params.get("uvasize").toString();
-        int size = Integer.parseInt(uvasize);
-        //������
-        ArrayList<Double> flyLatList = new ArrayList<>();
-        //������
-        ArrayList<Double> flyLonList = new ArrayList<>();
-
-        List<HistorySecondUav> historySecondUavs = historySecondUavMapper.reList(params);
-        ArrayList<UAVGetBD> rsBDList = new ArrayList<>();
-        for (HistorySecondUav historySecondUav : historySecondUavs) {
-            UAVGetBD uavGetBD = new UAVGetBD();
-            String value = historySecondUav.getValue();
-            JSONObject jsonObject = JSONObject.parseObject(value);
-
-            String flylon = jsonObject.get("flylon").toString();
-            String flylat = jsonObject.get("flylat").toString();
-            //WGS84 ��� ������������
-            double[] doubles = transformWGS84ToBD09(Double.parseDouble(flylon), Double.parseDouble(flylat));
-            uavGetBD.setFlyLon(doubles[0]);
-            uavGetBD.setFlyLat(doubles[1]);
-            uavGetBD.setTime(DateUtils.dateToDateString(historySecondUav.getTime()));
-            uavGetBD.setValue(value);
-            rsBDList.add(uavGetBD);
-//            flyLatList.add(Double.parseDouble(flylat));
-//            flyLonList.add(Double.parseDouble(flylon));
-            flyLatList.add(doubles[1]);
-            flyLonList.add(doubles[0]);
+        List<UAVResultDTO> uavResultDTOS = uavService.getUav(params);
+        if (ObjectUtils.isEmpty(uavResultDTOS)){
+            return new ResultMessage(ResponseCodeEnum.SENSOR_IS_NOT_EXIST,"null");
         }
-        if (ObjectUtils.isEmpty(historySecondUavs)){
-            return new ResultMessage(ResponseCodeEnum.TARGET_IS_NULL,"null");
-        }
-        //������������������������������
-        Double maxLat = Collections.max(flyLatList);
-        Double maxLon = Collections.max(flyLonList);
-        Double minLat = Collections.min(flyLatList);
-        Double minLon = Collections.min(flyLonList);
-        //������������������
-//        String leftTop =  minLat +";"+ maxLon;
-        //������
-//        String rightTop =  maxLat +";"+ maxLon;
-        //������
-//        String leftBottom = minLat +";" + minLon;
-        //������
-//        String rightBottom = maxLat +";" + minLon;
-        //���������������������
-        double distance1 = getDistance(maxLon, minLat, maxLon, maxLat);
-        //���������������������
-        double distance2 = getDistance(maxLon, minLat, minLon, minLat);
-        ArrayList<UAVGteForDTO> list = new ArrayList<>();
-        //������������
-
-//        String [] lefts =new String[]{maxLon.toString(),minLat.toString()};
-        //������2
-        String[] youshang = calLocationByDistanceAndLocationAndDirection(90, minLon, maxLat, size);
-        //������2
-        String[] youxia = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(youshang[0]), Double.parseDouble(youshang[1]), size);
-        //������2
-        String[] zuoxia = calLocationByDistanceAndLocationAndDirection(180, minLon, maxLat, size);
-
-        for (int i = 0; i <distance2 ; i+=size) {
-            UAVGteForDTO dto1 = new UAVGteForDTO();
-            String[] strings2 = calLocationByDistanceAndLocationAndDirection(90, minLon, maxLat, i);
-            String[] strings3 = calLocationByDistanceAndLocationAndDirection(90, Double.parseDouble(youshang[0].toString()), Double.parseDouble(youshang[1].toString()), i);
-            String[] strings4 = calLocationByDistanceAndLocationAndDirection(90, Double.parseDouble(youxia[0].toString()), Double.parseDouble(youxia[1].toString()), i);
-            String[] strings5 = calLocationByDistanceAndLocationAndDirection(90, Double.parseDouble(zuoxia[0].toString()), Double.parseDouble(zuoxia[1].toString()), i);
-            dto1.setLeftTop(strings2);
-            dto1.setRightTop(strings3);
-            dto1.setRightBottom(strings4);
-            dto1.setLeftBottom(strings5);
-            list.add(dto1);
-            for (int j = 0; j < distance1; j+=size) {
-                UAVGteForDTO dto2 = new UAVGteForDTO();
-                String[] strings6 = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(strings2[0].toString()), Double.parseDouble(strings2[1].toString()), j);
-                String[] strings7 = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(strings3[0].toString()), Double.parseDouble(strings3[1].toString()), j);
-                String[] strings8 = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(strings4[0].toString()), Double.parseDouble(strings4[1].toString()), j);
-                String[] strings9 = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(strings5[0].toString()), Double.parseDouble(strings5[1].toString()), j);
-                dto2.setLeftTop(strings6);
-                dto2.setRightTop(strings7);
-                dto2.setRightBottom(strings8);
-                dto2.setLeftBottom(strings9);
-                if (j!=0){
-                list.add(dto2);
-                }
-            }
-        }
-        HashMap<String,List<String>> rsMap = new HashMap<>();
-        List<String>  stringList = new ArrayList<>();
-        for (UAVGteForDTO uavGteForDTO : list) {
-            ArrayList<String> list1 = new ArrayList<>();
-            ArrayList<String[]> doubleArrayList = new ArrayList<>();
-            doubleArrayList.add(uavGteForDTO.getLeftTop());
-            doubleArrayList.add(uavGteForDTO.getLeftBottom());
-            doubleArrayList.add(uavGteForDTO.getRightTop());
-            doubleArrayList.add(uavGteForDTO.getRightBottom());
-            String[] leftTops = uavGteForDTO.getLeftTop();
-            String[] rightBottoms = uavGteForDTO.getRightBottom();
-            Double x1 = Double.parseDouble(leftTops[0]);
-            Double x2 = Double.parseDouble(rightBottoms[0]);
-            Double y1 = Double.parseDouble(leftTops[1]);
-            Double y2 = Double.parseDouble(rightBottoms[1]);
-            //������������������
-//            for (int i = 0; i < historySecondUavs.size(); i++) {
-//                HistorySecondUav historySecondUav = historySecondUavs.get(i);
-//                String value = historySecondUav.getValue();
-//                Map map1 = JSON.parseObject(value, Map.class);
-//                String flylat = map1.get("flylat").toString();
-//                String flylon = map1.get("flylon").toString();
-//                //���������������������������
-//                boolean flag = isInPolygon(flylon,flylat,x1,x2,y1,y2);
-//                if (flag){
-//                    String time = DateUtils.dateToDateString(historySecondUav.getTime());
-//                    //historySecondUavs.remove(i);
-//                    if(!stringList.contains(time)){
-//                        list1.add(historySecondUav.getValue());
-//                        stringList.add(time);
-//                    }
-//                }
-//            }
-            for (UAVGetBD uavGetBD : rsBDList) {
-                boolean flag = isInPolygon(uavGetBD.getFlyLon().toString(),uavGetBD.getFlyLat().toString(),x1,x2,y1,y2);
-                if (flag){
-                    String time = uavGetBD.getTime();
-                    //historySecondUavs.remove(i);
-                    if(!stringList.contains(time)){
-                        list1.add(uavGetBD.getValue());
-                        stringList.add(time);
-                    }
-                }
-            }
-            //���������������������
-            String result = getResult(doubleArrayList);
-            rsMap.put(result,list1);
-        }
-
-        //���������������������������������������
-        ArrayList<UAVResultDTO> uavResultDTOS = new ArrayList<>();
-        Set<String> strings = rsMap.keySet();
-        for (String string : strings) {
-            UAVResultDTO dto = new UAVResultDTO();
-            List<String> list1 = rsMap.get(string);
-            if (ObjectUtils.isEmpty(list1)){
-                continue;
-            }
-            ArrayList<Double> TVOCArrayList = new ArrayList<>();
-            ArrayList<Double> PM10ArrayList = new ArrayList<>();
-            ArrayList<Double> PM25ArrayList = new ArrayList<>();
-            ArrayList<Double> SOArrayList = new ArrayList<>();
-            ArrayList<Double> NOArrayList = new ArrayList<>();
-            ArrayList<Double> QYArrayList = new ArrayList<>();
-            ArrayList<Double> COArrayList = new ArrayList<>();
-            ArrayList<Double> WDArrayList = new ArrayList<>();
-            ArrayList<Double> SHArrayList = new ArrayList<>();
-            ArrayList<Double> O3ArrayList = new ArrayList<>();
-            for (String s : list1) {
-                JSONObject jsonObject = JSON.parseObject(s);
-                //tvoc
-                Object a99054 = jsonObject.get("a99054");
-                if (!Objects.isNull(a99054)){
-                    TVOCArrayList.add(Double.parseDouble(a99054.toString()));
-                }
-                //pm2.5
-                Object a34004 = jsonObject.get("a34004");
-                if (!Objects.isNull(a34004)){
-                    PM25ArrayList.add(Double.parseDouble(a34004.toString()));
-                }
-                //������������
-                Object a21026 = jsonObject.get("a21026");
-                if (!Objects.isNull(a21026)){
-                    SOArrayList.add(Double.parseDouble(a21026.toString()));
-                }
-
-                //������������
-                Object a21004 = jsonObject.get("a21004");
-                if (!Objects.isNull(a21004)){
-                    NOArrayList.add(Double.parseDouble(a21004.toString()));
-                }
-
-                //������
-                Object a01006 = jsonObject.get("a01006");
-                if (!Objects.isNull(a01006)){
-                    QYArrayList.add(Double.parseDouble(a01006.toString()));
-                }
-                //pm10
-                Object a34002 = jsonObject.get("a34002");
-                if (!Objects.isNull(a34002)){
-                    PM10ArrayList.add(Double.parseDouble(a34002.toString()));
-                }
-                //co
-                Object a21005 = jsonObject.get("a21005");
-                if (!Objects.isNull(a21005)){
-                    COArrayList.add(Double.parseDouble(a21005.toString()));
-                }
-                //������
-                Object a01002 = jsonObject.get("a01002");
-                if (!Objects.isNull(a01002)){
-                    QYArrayList.add(Double.parseDouble(a01002.toString()));
-                }
-                //������
-                Object a01001 = jsonObject.get("a01001");
-                if (!Objects.isNull(a01001)){
-                    QYArrayList.add(Double.parseDouble(a01001.toString()));
-                }
-                //������
-                Object a05024 = jsonObject.get("a05024");
-                if (!Objects.isNull(a05024)){
-                    O3ArrayList.add(Double.parseDouble(a05024.toString()));
-                }
-
-            }
-            double WDDouble =0.0;
-            double SHDouble =0.0;
-            double QYDouble =0.0;
-            double CODouble =0.0;
-            double TVODouble =0.0;
-            double PM10Double =0.0;
-            double PM25Double =0.0;
-            double SODouble =0.0;
-            double NODouble =0.0;
-            double O3Double =0.0;
-            if (COArrayList.size()>0){
-                CODouble = COArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
-            }
-            if (TVOCArrayList.size()>0){
-                TVODouble = TVOCArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
-            }
-            if (PM10ArrayList.size()>0){
-                PM10Double = PM10ArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
-            }
-            if (PM25ArrayList.size()>0){
-                PM25Double = PM25ArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
-            }
-            if (SOArrayList.size()>0){
-                SODouble = SOArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
-            }
-            if (NOArrayList.size()>0){
-                NODouble = NOArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
-            }
-            if (WDArrayList.size()>0){
-                 WDDouble = WDArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
-            }
-            if (SHArrayList.size()>0){
-                SHDouble = SHArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
-            }
-            if (QYArrayList.size()>0){
-                QYDouble = QYArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
-            }
-            if (O3ArrayList.size()>0){
-                O3Double = O3ArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
-            }
-
-            dto.setA21005(CODouble);
-            dto.setA21004(NODouble);
-            dto.setA05024(O3Double);
-            dto.setA99054(TVODouble);
-            dto.setA34002(PM10Double);
-            dto.setA34004(PM25Double);
-            dto.setA21026(SODouble);
-            dto.setA01001(WDDouble);
-            dto.setA01002(SHDouble);
-            dto.setA01006(QYDouble);
-            String[] s = string.split("_");
-            dto.setFlyLat(Double.parseDouble(s[1]));
-            dto.setFlyLon(Double.parseDouble(s[0]));
-            uavResultDTOS.add(dto);
-        }
-
-
         return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),uavResultDTOS);
     }
 
@@ -395,349 +135,5 @@
         return new ResultMessage(ResponseCodeEnum.SUCCESS.getCode(), ResponseCodeEnum.SUCCESS.getMsg(),vo);
     }
 
-    private static final double EARTH_RADIUS = 6378137;
-
-    private static final double R = 6371e3;
-    /** 180�� **/
-    private static final DecimalFormat df = new DecimalFormat("0.00000000");
-
-    /**
-     * ���������������������������������������������������������������������������
-     * @param angle ���������������������������������������������
-     * @param startLong ���������������
-     * @param startLat ���������������
-     * @param distance ���������������m
-     * @return
-     */
-    public static String[] calLocationByDistanceAndLocationAndDirection(double angle, double startLong,double startLat, double distance){
-        String[] result = new String[2];
-        //���������������������������������������
-        double �� = distance/R;
-        // ���������radian���������������������������
-        angle = Math.toRadians(angle);
-        startLong = Math.toRadians(startLong);
-        startLat = Math.toRadians(startLat);
-        double lat = Math.asin(Math.sin(startLat)*Math.cos(��)+Math.cos(startLat)*Math.sin(��)*Math.cos(angle));
-        double lon = startLong + Math.atan2(Math.sin(angle)*Math.sin(��)*Math.cos(startLat),Math.cos(��)-Math.sin(startLat)*Math.sin(lat));
-        // ���������������10���������������
-        lon = Math.toDegrees(lon);
-        lat = Math.toDegrees(lat);
-        result[0] = df.format(lon);
-        result[1] = df.format(lat);
-        return result;
-    }
-
-    /**
-     * ������������������������������������������
-     *
-     * @param longitude1 ���������������������
-     * @param latitude1  ���������������������
-     * @param longitude2 ���������������������
-     * @param latitude2  ���������������������
-     * @return ������������ ���������
-     */
-    public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) {
-        // ������
-        double lat1 = Math.toRadians(latitude1);
-        double lat2 = Math.toRadians(latitude2);
-        // ������
-        double lng1 = Math.toRadians(longitude1);
-        double lng2 = Math.toRadians(longitude2);
-        // ������������
-        double a = lat1 - lat2;
-        // ������������
-        double b = lng1 - lng2;
-        // ���������������������������
-        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
-                Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
-        // ���������������������, ������������: ���
-        s =  s * EARTH_RADIUS;
-        return s;
-    }
-
-    //���������������
-    public static String getResult(ArrayList<String[]> doubleArrayList){
-
-            int total = doubleArrayList.size();
-            double X = 0, Y = 0, Z = 0;
-            for (int i = 0; i < total; i++) {
-                double lat, lon, x, y, z;
-                String[] strings = doubleArrayList.get(i);
-                lon = Double.parseDouble(strings[0]) * Math.PI / 180;
-                lat = Double.parseDouble(strings[1]) * Math.PI / 180;
-                x = Math.cos(lat) * Math.cos(lon);
-                y = Math.cos(lat) * Math.sin(lon);
-                z = Math.sin(lat);
-                X += x;
-                Y += y;
-                Z += z;
-            }
-            X = X / total;
-            Y = Y / total;
-            Z = Z / total;
-            double Lon = Math.atan2(Y, X);
-            double Hyp = Math.sqrt(X * X + Y * Y);
-            double Lat = Math.atan2(Z, Hyp);
-        DecimalFormat decimalFormat = new DecimalFormat("#.00000000");
-        double rsLon = Lon * 180 / Math.PI;
-        double rsLat = Lat * 180 / Math.PI;
-
-//        double[] doubles = transformWGS84ToGCJ02(rsLon, rsLat);
-//        String s = transformGCJ02ToBD09(doubles[0], doubles[1]);
-
-
-        return decimalFormat.format(rsLon)+"_"+decimalFormat.format(rsLat);
-//        return rsLon+"_"+rsLat;
-//        return s;
-    }
-
-
-    //���������������
-    public static UAVResultDTO getResults(ArrayList<String[]> doubleArrayList){
-        UAVResultDTO uavResultDTO = new UAVResultDTO();
-        int total = doubleArrayList.size();
-        double X = 0, Y = 0, Z = 0;
-        for (int i = 0; i < total; i++) {
-            double lat, lon, x, y, z;
-            String[] strings = doubleArrayList.get(i);
-            lon = Double.parseDouble(strings[0]) * Math.PI / 180;
-            lat = Double.parseDouble(strings[1]) * Math.PI / 180;
-            x = Math.cos(lat) * Math.cos(lon);
-            y = Math.cos(lat) * Math.sin(lon);
-            z = Math.sin(lat);
-            X += x;
-            Y += y;
-            Z += z;
-        }
-        X = X / total;
-        Y = Y / total;
-        Z = Z / total;
-        double Lon = Math.atan2(Y, X);
-        double Hyp = Math.sqrt(X * X + Y * Y);
-        double Lat = Math.atan2(Z, Hyp);
-
-        double rsLon = Lon * 180 / Math.PI;
-        double rsLat = Lat * 180 / Math.PI;
-        uavResultDTO.setFlyLon(rsLon);
-        uavResultDTO.setFlyLat(rsLat);
-
-//        return rsLon+"_"+rsLat;
-        return uavResultDTO;
-    }
-
-    /**
-     * ������������������������������GeneralPath������
-     *
-     * @param points ���������(������)
-     *
-     * @return GeneralPath������
-     */
-    public static GeneralPath genGeneralPath(ArrayList<Point2D.Double> points) {
-        GeneralPath path = new GeneralPath();
-
-        if (points.size() < 3) {
-            return null;
-        }
-
-        path.moveTo((float) points.get(0).getX(), (float) points.get(0).getY());
-
-        for (Iterator<Point2D.Double> it = points.iterator(); it.hasNext();) {
-            Point2D.Double point = (Point2D.Double) it.next();
-
-            path.lineTo((float) point.getX(), (float) point.getY());
-        }
-
-        path.closePath();
-
-        return path;
-    }
-    /**
-     * ������������������������������������������������������������������������������������������������������������������������true
-     * @param point ���������
-     * @param pts   ������������������
-     * @return      ������������������������true,������������false
-     */
-    public static boolean IsPtInPoly(Point2D.Double point, List<Point2D.Double> pts){
-
-        int N = pts.size();
-        boolean boundOrVertex = true; //���������������������������������������������������������������������������������������true
-        int intersectCount = 0;//cross points count of x
-        double precision = 2e-10; //���������������������������0���������������������
-        Point2D.Double p1, p2;//neighbour bound vertices
-        Point2D.Double p = point; //���������
-
-        p1 = pts.get(0);//left vertex
-        for(int i = 1; i <= N; ++i){//check all rays
-            if(p.equals(p1)){
-                return boundOrVertex;//p is an vertex
-            }
-
-            p2 = pts.get(i % N);
-            if(p.x < Math.min(p1.x, p2.x) || p.x > Math.max(p1.x, p2.x)){
-                p1 = p2;
-                continue;
-            }
-
-            if(p.x > Math.min(p1.x, p2.x) && p.x < Math.max(p1.x, p2.x)){
-                if(p.y <= Math.max(p1.y, p2.y)){
-                    if(p1.x == p2.x && p.y >= Math.min(p1.y, p2.y)){
-                        return boundOrVertex;
-                    }
-
-                    if(p1.y == p2.y){
-                        if(p1.y == p.y){
-                            return boundOrVertex;
-                        }else{//before ray
-                            ++intersectCount;
-                        }
-                    }else{
-                        double xinters = (p.x - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
-                        if(Math.abs(p.y - xinters) < precision){
-                            return boundOrVertex;
-                        }
-
-                        if(p.y < xinters){
-                            ++intersectCount;
-                        }
-                    }
-                }
-            }else{
-                if(p.x == p2.x && p.y <= p2.y){
-                    Point2D.Double p3 = pts.get((i+1) % N);
-                    if(p.x >= Math.min(p1.x, p3.x) && p.x <= Math.max(p1.x, p3.x)){
-                        ++intersectCount;
-                    }else{
-                        intersectCount += 2;
-                    }
-                }
-            }
-            p1 = p2;
-        }
-
-        if(intersectCount % 2 == 0){//���������������������
-            return false;
-        } else { //���������������������
-            return true;
-        }
-    }
-
-    /**
-     * ���������������������������������������������
-     * @param
-     * @param doubleArrayList ������������
-     * @return
-     */
-    public static boolean isInPolygon(String X,String Y,ArrayList<String[]> doubleArrayList){
-
-        double p_x =Double.parseDouble(X);
-        double p_y =Double.parseDouble(Y);
-        Point2D.Double point = new Point2D.Double(p_x, p_y);
-        List<Point2D.Double> pointList= new ArrayList<Point2D.Double>();
-        for (String[] strings : doubleArrayList) {
-            double polygonPoint_x=Double.parseDouble(strings[0]);
-            double polygonPoint_y=Double.parseDouble(strings[1]);
-            Point2D.Double polygonPoint = new Point2D.Double(polygonPoint_x,polygonPoint_y);
-            pointList.add(polygonPoint);
-        }
-        return IsPtInPoly(point,pointList);
-
-    }
-
-    public boolean isInPolygon(String X,String Y,double x1,double x2,double y1,double y2){
-        boolean result = false;
-        double x =Double.parseDouble(X);
-        double y =Double.parseDouble(Y);
-        if(x >= Math.min(x1, x2) && x <= Math.max(x1, x2) ){
-            if(y >= Math.min(y1, y2) && y <= Math.max(y1, y2)){
-                result = true;
-            }
-        }
-        return result;
-
-    }
-
-    private static final double x_PI = 3.14159265358979324 * 3000.0 / 180.0;
-    private static final double PI = 3.1415926535897932384626;
-    private static final double a = 6378245.0;
-    private static final double ee = 0.00669342162296594323;
-    /**
-     * WGS84 ������ ��� GCJ02
-     *
-     * @param lng ������
-     * @param lat ������
-     * @return GCJ02 ���������[���������������]
-     */
-    public static double[] transformWGS84ToGCJ02(double lng, double lat) {
-        if (outOfChina(lng, lat)) {
-            return new double[]{lng, lat};
-        } else {
-            double dLat = transformLat(lng - 105.0, lat - 35.0);
-            double dLng = transformLng(lng - 105.0, lat - 35.0);
-            double redLat = lat / 180.0 * PI;
-            double magic = Math.sin(redLat);
-            magic = 1 - ee * magic * magic;
-            double sqrtMagic = Math.sqrt(magic);
-            dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI);
-            dLng = (dLng * 180.0) / (a / sqrtMagic * Math.cos(redLat) * PI);
-            double mgLat = lat + dLat;
-            double mgLng = lng + dLng;
-            return new double[]{mgLng, mgLat};
-        }
-    }
-
-    private static double transformLat(double lng, double lat) {
-        double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
-        ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
-        ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
-        ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
-        return ret;
-    }
-
-    private static double transformLng(double lng, double lat) {
-        double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
-        ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
-        ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
-        ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
-        return ret;
-    }
-    /**
-     * ������������������������������
-     *
-     * @param lng ������
-     * @param lat ������
-     * @return ���������������������
-     */
-    public static boolean outOfChina(double lng, double lat) {
-        return (lng < 72.004 || lng > 137.8347) || (lat < 0.8293 || lat > 55.8271);
-    }
-
-    /**
-     * GCJ02 ���������������
-     *
-     * @param lng GCJ02 ������
-     * @param lat GCJ02 ������
-     * @return ���������������[���������������]
-     */
-    public static double[] transformGCJ02ToBD09(double lng, double lat) {
-        double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
-        double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
-        double bd_lng = z * Math.cos(theta) + 0.0065;
-        double bd_lat = z * Math.sin(theta) + 0.006;
-        return new double[]{bd_lng, bd_lat};
-    }
-
-
-    /**
-     * WGS84 ��� ������������BD09
-     *
-     * @param lng ������
-     * @param lat ������
-     * @return BD09 ���������[���������������]
-     */
-    public static double[] transformWGS84ToBD09(double lng, double lat) {
-        double[] lngLat = transformWGS84ToGCJ02(lng, lat);
-
-        return transformGCJ02ToBD09(lngLat[0], lngLat[1]);
-    }
 
 }
diff --git a/screen-api/src/main/java/com/moral/api/service/UAVService.java b/screen-api/src/main/java/com/moral/api/service/UAVService.java
new file mode 100644
index 0000000..dee6115
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/service/UAVService.java
@@ -0,0 +1,13 @@
+package com.moral.api.service;
+
+
+import java.util.List;
+import java.util.Map;
+
+import com.moral.api.pojo.dto.uav.UAVResultDTO;
+
+public interface UAVService {
+
+
+    List<UAVResultDTO> getUav(Map<String, Object> params);
+}
diff --git a/screen-api/src/main/java/com/moral/api/service/impl/UAVServiceImpl.java b/screen-api/src/main/java/com/moral/api/service/impl/UAVServiceImpl.java
new file mode 100644
index 0000000..97054b4
--- /dev/null
+++ b/screen-api/src/main/java/com/moral/api/service/impl/UAVServiceImpl.java
@@ -0,0 +1,509 @@
+package com.moral.api.service.impl;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.text.DecimalFormat;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.moral.api.entity.HistorySecondUav;
+import com.moral.api.mapper.HistorySecondUavMapper;
+import com.moral.api.pojo.dto.uav.UAVGetBD;
+import com.moral.api.pojo.dto.uav.UAVGteForDTO;
+import com.moral.api.pojo.dto.uav.UAVResultDTO;
+import com.moral.api.service.UAVService;
+import com.moral.util.DateUtils;
+
+
+@Service
+public class UAVServiceImpl implements UAVService {
+
+    @Autowired
+    private HistorySecondUavMapper historySecondUavMapper;
+
+    @Override
+    public List<UAVResultDTO> getUav(Map<String, Object> params) {
+
+        String uvasize = params.get("uvasize").toString();
+        int size = Integer.parseInt(uvasize);
+        //������
+        ArrayList<Double> flyLatList = new ArrayList<>();
+        //������
+        ArrayList<Double> flyLonList = new ArrayList<>();
+
+        List<HistorySecondUav> historySecondUavs = historySecondUavMapper.reList(params);
+        if (ObjectUtils.isEmpty(historySecondUavs)){
+            return null;
+        }
+        ArrayList<UAVGetBD> rsBDList = new ArrayList<>();
+        for (HistorySecondUav historySecondUav : historySecondUavs) {
+            UAVGetBD uavGetBD = new UAVGetBD();
+            String value = historySecondUav.getValue();
+            JSONObject jsonObject = JSONObject.parseObject(value);
+
+            String flylon = jsonObject.get("flylon").toString();
+            String flylat = jsonObject.get("flylat").toString();
+            //WGS84 ��� ������������
+            double[] doubles = transformWGS84ToBD09(Double.parseDouble(flylon), Double.parseDouble(flylat));
+            uavGetBD.setFlyLon(doubles[0]);
+            uavGetBD.setFlyLat(doubles[1]);
+            uavGetBD.setTime(DateUtils.dateToDateString(historySecondUav.getTime()));
+            uavGetBD.setValue(value);
+            rsBDList.add(uavGetBD);
+//            flyLatList.add(Double.parseDouble(flylat));
+//            flyLonList.add(Double.parseDouble(flylon));
+            flyLatList.add(doubles[1]);
+            flyLonList.add(doubles[0]);
+        }
+        //������������������������������
+        Double maxLat = Collections.max(flyLatList);
+        Double maxLon = Collections.max(flyLonList);
+        Double minLat = Collections.min(flyLatList);
+        Double minLon = Collections.min(flyLonList);
+        //������������������
+//        String leftTop =  minLat +";"+ maxLon;
+        //������
+//        String rightTop =  maxLat +";"+ maxLon;
+        //������
+//        String leftBottom = minLat +";" + minLon;
+        //������
+//        String rightBottom = maxLat +";" + minLon;
+        //���������������������
+        double distance1 = getDistance(maxLon, minLat, maxLon, maxLat);
+        //���������������������
+        double distance2 = getDistance(maxLon, minLat, minLon, minLat);
+        ArrayList<UAVGteForDTO> list = new ArrayList<>();
+        //������������
+
+//        String [] lefts =new String[]{maxLon.toString(),minLat.toString()};
+        //������2
+        String[] youshang = calLocationByDistanceAndLocationAndDirection(90, minLon, maxLat, size);
+        //������2
+        String[] youxia = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(youshang[0]), Double.parseDouble(youshang[1]), size);
+        //������2
+        String[] zuoxia = calLocationByDistanceAndLocationAndDirection(180, minLon, maxLat, size);
+
+        for (int i = 0; i <distance2 ; i+=size) {
+            UAVGteForDTO dto1 = new UAVGteForDTO();
+            String[] strings2 = calLocationByDistanceAndLocationAndDirection(90, minLon, maxLat, i);
+            String[] strings3 = calLocationByDistanceAndLocationAndDirection(90, Double.parseDouble(youshang[0].toString()), Double.parseDouble(youshang[1].toString()), i);
+            String[] strings4 = calLocationByDistanceAndLocationAndDirection(90, Double.parseDouble(youxia[0].toString()), Double.parseDouble(youxia[1].toString()), i);
+            String[] strings5 = calLocationByDistanceAndLocationAndDirection(90, Double.parseDouble(zuoxia[0].toString()), Double.parseDouble(zuoxia[1].toString()), i);
+            dto1.setLeftTop(strings2);
+            dto1.setRightTop(strings3);
+            dto1.setRightBottom(strings4);
+            dto1.setLeftBottom(strings5);
+            list.add(dto1);
+            for (int j = 0; j < distance1; j+=size) {
+                UAVGteForDTO dto2 = new UAVGteForDTO();
+                String[] strings6 = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(strings2[0].toString()), Double.parseDouble(strings2[1].toString()), j);
+                String[] strings7 = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(strings3[0].toString()), Double.parseDouble(strings3[1].toString()), j);
+                String[] strings8 = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(strings4[0].toString()), Double.parseDouble(strings4[1].toString()), j);
+                String[] strings9 = calLocationByDistanceAndLocationAndDirection(180, Double.parseDouble(strings5[0].toString()), Double.parseDouble(strings5[1].toString()), j);
+                dto2.setLeftTop(strings6);
+                dto2.setRightTop(strings7);
+                dto2.setRightBottom(strings8);
+                dto2.setLeftBottom(strings9);
+                if (j!=0){
+                    list.add(dto2);
+                }
+            }
+        }
+        HashMap<String,List<String>> rsMap = new HashMap<>();
+        List<String>  stringList = new ArrayList<>();
+        for (UAVGteForDTO uavGteForDTO : list) {
+            ArrayList<String> list1 = new ArrayList<>();
+            ArrayList<String[]> doubleArrayList = new ArrayList<>();
+            doubleArrayList.add(uavGteForDTO.getLeftTop());
+            doubleArrayList.add(uavGteForDTO.getLeftBottom());
+            doubleArrayList.add(uavGteForDTO.getRightTop());
+            doubleArrayList.add(uavGteForDTO.getRightBottom());
+            String[] leftTops = uavGteForDTO.getLeftTop();
+            String[] rightBottoms = uavGteForDTO.getRightBottom();
+            Double x1 = Double.parseDouble(leftTops[0]);
+            Double x2 = Double.parseDouble(rightBottoms[0]);
+            Double y1 = Double.parseDouble(leftTops[1]);
+            Double y2 = Double.parseDouble(rightBottoms[1]);
+            //������������������
+//            for (int i = 0; i < historySecondUavs.size(); i++) {
+//                HistorySecondUav historySecondUav = historySecondUavs.get(i);
+//                String value = historySecondUav.getValue();
+//                Map map1 = JSON.parseObject(value, Map.class);
+//                String flylat = map1.get("flylat").toString();
+//                String flylon = map1.get("flylon").toString();
+//                //���������������������������
+//                boolean flag = isInPolygon(flylon,flylat,x1,x2,y1,y2);
+//                if (flag){
+//                    String time = DateUtils.dateToDateString(historySecondUav.getTime());
+//                    //historySecondUavs.remove(i);
+//                    if(!stringList.contains(time)){
+//                        list1.add(historySecondUav.getValue());
+//                        stringList.add(time);
+//                    }
+//                }
+//            }
+            for (UAVGetBD uavGetBD : rsBDList) {
+                boolean flag = isInPolygon(uavGetBD.getFlyLon().toString(),uavGetBD.getFlyLat().toString(),x1,x2,y1,y2);
+                if (flag){
+                    String time = uavGetBD.getTime();
+                    //historySecondUavs.remove(i);
+                    if(!stringList.contains(time)){
+                        list1.add(uavGetBD.getValue());
+                        stringList.add(time);
+                    }
+                }
+            }
+            //���������������������
+            String result = getResult(doubleArrayList);
+            rsMap.put(result,list1);
+        }
+
+        //���������������������������������������
+        ArrayList<UAVResultDTO> uavResultDTOS = new ArrayList<>();
+        Set<String> strings = rsMap.keySet();
+        for (String string : strings) {
+            UAVResultDTO dto = new UAVResultDTO();
+            List<String> list1 = rsMap.get(string);
+            if (ObjectUtils.isEmpty(list1)){
+                continue;
+            }
+            ArrayList<Double> TVOCArrayList = new ArrayList<>();
+            ArrayList<Double> PM10ArrayList = new ArrayList<>();
+            ArrayList<Double> PM25ArrayList = new ArrayList<>();
+            ArrayList<Double> SOArrayList = new ArrayList<>();
+            ArrayList<Double> NOArrayList = new ArrayList<>();
+            ArrayList<Double> QYArrayList = new ArrayList<>();
+            ArrayList<Double> COArrayList = new ArrayList<>();
+            ArrayList<Double> WDArrayList = new ArrayList<>();
+            ArrayList<Double> SHArrayList = new ArrayList<>();
+            ArrayList<Double> O3ArrayList = new ArrayList<>();
+            for (String s : list1) {
+                JSONObject jsonObject = JSON.parseObject(s);
+                //tvoc
+                Object a99054 = jsonObject.get("a99054");
+                if (!Objects.isNull(a99054)){
+                    TVOCArrayList.add(Double.parseDouble(a99054.toString()));
+                }
+                //pm2.5
+                Object a34004 = jsonObject.get("a34004");
+                if (!Objects.isNull(a34004)){
+                    PM25ArrayList.add(Double.parseDouble(a34004.toString()));
+                }
+                //������������
+                Object a21026 = jsonObject.get("a21026");
+                if (!Objects.isNull(a21026)){
+                    SOArrayList.add(Double.parseDouble(a21026.toString()));
+                }
+
+                //������������
+                Object a21004 = jsonObject.get("a21004");
+                if (!Objects.isNull(a21004)){
+                    NOArrayList.add(Double.parseDouble(a21004.toString()));
+                }
+
+                //������
+                Object a01006 = jsonObject.get("a01006");
+                if (!Objects.isNull(a01006)){
+                    QYArrayList.add(Double.parseDouble(a01006.toString()));
+                }
+                //pm10
+                Object a34002 = jsonObject.get("a34002");
+                if (!Objects.isNull(a34002)){
+                    PM10ArrayList.add(Double.parseDouble(a34002.toString()));
+                }
+                //co
+                Object a21005 = jsonObject.get("a21005");
+                if (!Objects.isNull(a21005)){
+                    COArrayList.add(Double.parseDouble(a21005.toString()));
+                }
+                //������
+                Object a01002 = jsonObject.get("a01002");
+                if (!Objects.isNull(a01002)){
+                    QYArrayList.add(Double.parseDouble(a01002.toString()));
+                }
+                //������
+                Object a01001 = jsonObject.get("a01001");
+                if (!Objects.isNull(a01001)){
+                    QYArrayList.add(Double.parseDouble(a01001.toString()));
+                }
+                //������
+                Object a05024 = jsonObject.get("a05024");
+                if (!Objects.isNull(a05024)){
+                    O3ArrayList.add(Double.parseDouble(a05024.toString()));
+                }
+
+            }
+            double WDDouble =0.0;
+            double SHDouble =0.0;
+            double QYDouble =0.0;
+            double CODouble =0.0;
+            double TVODouble =0.0;
+            double PM10Double =0.0;
+            double PM25Double =0.0;
+            double SODouble =0.0;
+            double NODouble =0.0;
+            double O3Double =0.0;
+            if (COArrayList.size()>0){
+                CODouble = COArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
+            }
+            if (TVOCArrayList.size()>0){
+                TVODouble = TVOCArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
+            }
+            if (PM10ArrayList.size()>0){
+                PM10Double = PM10ArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
+            }
+            if (PM25ArrayList.size()>0){
+                PM25Double = PM25ArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
+            }
+            if (SOArrayList.size()>0){
+                SODouble = SOArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
+            }
+            if (NOArrayList.size()>0){
+                NODouble = NOArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
+            }
+            if (WDArrayList.size()>0){
+                WDDouble = WDArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
+            }
+            if (SHArrayList.size()>0){
+                SHDouble = SHArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
+            }
+            if (QYArrayList.size()>0){
+                QYDouble = QYArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
+            }
+            if (O3ArrayList.size()>0){
+                O3Double = O3ArrayList.stream().mapToDouble(Double::doubleValue).average().getAsDouble();
+            }
+
+            dto.setA21005(CODouble);
+            dto.setA21004(NODouble);
+            dto.setA05024(O3Double);
+            dto.setA99054(TVODouble);
+            dto.setA34002(PM10Double);
+            dto.setA34004(PM25Double);
+            dto.setA21026(SODouble);
+            dto.setA01001(WDDouble);
+            dto.setA01002(SHDouble);
+            dto.setA01006(QYDouble);
+            String[] s = string.split("_");
+            dto.setFlyLat(Double.parseDouble(s[1]));
+            dto.setFlyLon(Double.parseDouble(s[0]));
+            uavResultDTOS.add(dto);
+        }
+        return uavResultDTOS;
+    }
+
+
+    private static final double EARTH_RADIUS = 6378137;
+
+    private static final double R = 6371e3;
+    /** 180�� **/
+    private static final DecimalFormat df = new DecimalFormat("0.00000000");
+
+    /**
+     * ���������������������������������������������������������������������������
+     * @param angle ���������������������������������������������
+     * @param startLong ���������������
+     * @param startLat ���������������
+     * @param distance ���������������m
+     * @return
+     */
+    public static String[] calLocationByDistanceAndLocationAndDirection(double angle, double startLong,double startLat, double distance){
+        String[] result = new String[2];
+        //���������������������������������������
+        double �� = distance/R;
+        // ���������radian���������������������������
+        angle = Math.toRadians(angle);
+        startLong = Math.toRadians(startLong);
+        startLat = Math.toRadians(startLat);
+        double lat = Math.asin(Math.sin(startLat)*Math.cos(��)+Math.cos(startLat)*Math.sin(��)*Math.cos(angle));
+        double lon = startLong + Math.atan2(Math.sin(angle)*Math.sin(��)*Math.cos(startLat),Math.cos(��)-Math.sin(startLat)*Math.sin(lat));
+        // ���������������10���������������
+        lon = Math.toDegrees(lon);
+        lat = Math.toDegrees(lat);
+        result[0] = df.format(lon);
+        result[1] = df.format(lat);
+        return result;
+    }
+
+    /**
+     * ������������������������������������������
+     *
+     * @param longitude1 ���������������������
+     * @param latitude1  ���������������������
+     * @param longitude2 ���������������������
+     * @param latitude2  ���������������������
+     * @return ������������ ���������
+     */
+    public static double getDistance(double longitude1, double latitude1, double longitude2, double latitude2) {
+        // ������
+        double lat1 = Math.toRadians(latitude1);
+        double lat2 = Math.toRadians(latitude2);
+        // ������
+        double lng1 = Math.toRadians(longitude1);
+        double lng2 = Math.toRadians(longitude2);
+        // ������������
+        double a = lat1 - lat2;
+        // ������������
+        double b = lng1 - lng2;
+        // ���������������������������
+        double s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a / 2), 2) +
+                Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(b / 2), 2)));
+        // ���������������������, ������������: ���
+        s =  s * EARTH_RADIUS;
+        return s;
+    }
+
+
+    //���������������
+    public static String getResult(ArrayList<String[]> doubleArrayList){
+
+        int total = doubleArrayList.size();
+        double X = 0, Y = 0, Z = 0;
+        for (int i = 0; i < total; i++) {
+            double lat, lon, x, y, z;
+            String[] strings = doubleArrayList.get(i);
+            lon = Double.parseDouble(strings[0]) * Math.PI / 180;
+            lat = Double.parseDouble(strings[1]) * Math.PI / 180;
+            x = Math.cos(lat) * Math.cos(lon);
+            y = Math.cos(lat) * Math.sin(lon);
+            z = Math.sin(lat);
+            X += x;
+            Y += y;
+            Z += z;
+        }
+        X = X / total;
+        Y = Y / total;
+        Z = Z / total;
+        double Lon = Math.atan2(Y, X);
+        double Hyp = Math.sqrt(X * X + Y * Y);
+        double Lat = Math.atan2(Z, Hyp);
+        DecimalFormat decimalFormat = new DecimalFormat("#.00000000");
+        double rsLon = Lon * 180 / Math.PI;
+        double rsLat = Lat * 180 / Math.PI;
+
+//        double[] doubles = transformWGS84ToGCJ02(rsLon, rsLat);
+//        String s = transformGCJ02ToBD09(doubles[0], doubles[1]);
+
+
+        return decimalFormat.format(rsLon)+"_"+decimalFormat.format(rsLat);
+//        return rsLon+"_"+rsLat;
+//        return s;
+    }
+
+    /**
+     * ������������������������������
+     * @param X
+     * @param Y
+     * @param x1
+     * @param x2
+     * @param y1
+     * @param y2
+     * @return
+     */
+    public boolean isInPolygon(String X,String Y,double x1,double x2,double y1,double y2){
+        boolean result = false;
+        double x =Double.parseDouble(X);
+        double y =Double.parseDouble(Y);
+        if(x >= Math.min(x1, x2) && x <= Math.max(x1, x2) ){
+            if(y >= Math.min(y1, y2) && y <= Math.max(y1, y2)){
+                result = true;
+            }
+        }
+        return result;
+
+    }
+
+
+    private static final double x_PI = 3.14159265358979324 * 3000.0 / 180.0;
+    private static final double PI = 3.1415926535897932384626;
+    private static final double a = 6378245.0;
+    private static final double ee = 0.00669342162296594323;
+    /**
+     * WGS84 ������ ��� GCJ02
+     *
+     * @param lng ������
+     * @param lat ������
+     * @return GCJ02 ���������[���������������]
+     */
+    public static double[] transformWGS84ToGCJ02(double lng, double lat) {
+        if (outOfChina(lng, lat)) {
+            return new double[]{lng, lat};
+        } else {
+            double dLat = transformLat(lng - 105.0, lat - 35.0);
+            double dLng = transformLng(lng - 105.0, lat - 35.0);
+            double redLat = lat / 180.0 * PI;
+            double magic = Math.sin(redLat);
+            magic = 1 - ee * magic * magic;
+            double sqrtMagic = Math.sqrt(magic);
+            dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * PI);
+            dLng = (dLng * 180.0) / (a / sqrtMagic * Math.cos(redLat) * PI);
+            double mgLat = lat + dLat;
+            double mgLng = lng + dLng;
+            return new double[]{mgLng, mgLat};
+        }
+    }
+
+    private static double transformLat(double lng, double lat) {
+        double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat + 0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
+        ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
+        ret += (20.0 * Math.sin(lat * PI) + 40.0 * Math.sin(lat / 3.0 * PI)) * 2.0 / 3.0;
+        ret += (160.0 * Math.sin(lat / 12.0 * PI) + 320 * Math.sin(lat * PI / 30.0)) * 2.0 / 3.0;
+        return ret;
+    }
+
+    private static double transformLng(double lng, double lat) {
+        double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng + 0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
+        ret += (20.0 * Math.sin(6.0 * lng * PI) + 20.0 * Math.sin(2.0 * lng * PI)) * 2.0 / 3.0;
+        ret += (20.0 * Math.sin(lng * PI) + 40.0 * Math.sin(lng / 3.0 * PI)) * 2.0 / 3.0;
+        ret += (150.0 * Math.sin(lng / 12.0 * PI) + 300.0 * Math.sin(lng / 30.0 * PI)) * 2.0 / 3.0;
+        return ret;
+    }
+    /**
+     * ������������������������������
+     *
+     * @param lng ������
+     * @param lat ������
+     * @return ���������������������
+     */
+    public static boolean outOfChina(double lng, double lat) {
+        return (lng < 72.004 || lng > 137.8347) || (lat < 0.8293 || lat > 55.8271);
+    }
+
+    /**
+     * GCJ02 ���������������
+     *
+     * @param lng GCJ02 ������
+     * @param lat GCJ02 ������
+     * @return ���������������[���������������]
+     */
+    public static double[] transformGCJ02ToBD09(double lng, double lat) {
+        double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_PI);
+        double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_PI);
+        double bd_lng = z * Math.cos(theta) + 0.0065;
+        double bd_lat = z * Math.sin(theta) + 0.006;
+        return new double[]{bd_lng, bd_lat};
+    }
+
+
+    /**
+     * WGS84 ��� ������������BD09
+     *
+     * @param lng ������
+     * @param lat ������
+     * @return BD09 ���������[���������������]
+     */
+    public static double[] transformWGS84ToBD09(double lng, double lat) {
+        double[] lngLat = transformWGS84ToGCJ02(lng, lat);
+
+        return transformGCJ02ToBD09(lngLat[0], lngLat[1]);
+    }
+}

--
Gitblit v1.8.0