zoukankan      html  css  js  c++  java
  • JAVA获取多个经纬度的中心点

    import java.util.LinkedList;
    
    public class Test1 {
    
        /**
         * 位置实体类,根据自己的来即可
         */
        static class Position{
    
            /**
             * 纬度
             */
            private Double latitude;
    
            /**
             * 经度
             */
            private Double longitude;
    
            public Double getLatitude() {
                return latitude;
            }
    
            public void setLatitude(Double latitude) {
                this.latitude = latitude;
            }
    
            public Double getLongitude() {
                return longitude;
            }
    
            public void setLongitude(Double longitude) {
                this.longitude = longitude;
            }
    
            public Position(Double latitude, Double longitude) {
                this.latitude = latitude;
                this.longitude = longitude;
            }
        }
    
    
        /**
         *  取几个经纬度的中心点
         * @param postionList 经纬度的集合
         */
        public static void getCenterPoint(LinkedList<Position> postionList) {
            int total = postionList.size();
            double X = 0, Y = 0, Z = 0;
    
            while(!postionList.isEmpty()) {
                Position g = postionList.pollFirst();
                if(g != null) {
                    double lat, lon, x, y, z;
                    lat = g.getLatitude() * Math.PI / 180;
                    lon = g.getLongitude() * 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 longitude = Lon * 180 / Math.PI;
            double latitude = Lat * 180 / Math.PI;
            System.out.println("中心点经度:"+longitude);
            System.out.println("中心点纬度:"+latitude);
    
        }
    
    
        public static void main(String[] args) {
            LinkedList<Position> list=new LinkedList<>();
            list.add(new Position(35.1719916700000040,119.2328202000000200));
            list.add(new Position(35.1319216700000040,119.2925302000000200));
            list.add(new Position(35.1919216700000040,119.2625302000000200));
    
            getCenterPoint(list);
        }
    
    }
    -----------------------有任何问题可以在评论区评论,也可以私信我,我看到的话会进行回复,欢迎大家指教------------------------ (蓝奏云官网有些地址失效了,需要把请求地址lanzous改成lanzoux才可以)
  • 相关阅读:
    uwsgi配置
    sed_shell三剑客
    grep_shell三剑客
    awk_shell三剑客
    spring(二)
    spring(一)
    5G的科普
    应用层协议基础
    IP地址相关运算(如VLSM,超网汇总)
    ARP协议基础
  • 原文地址:https://www.cnblogs.com/pxblog/p/14635807.html
Copyright © 2011-2022 走看看