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);
}
}
JAVA获取多个经纬度的中心点的更多相关文章
- java根据地址获取百度API经纬度
java根据地址获取百度API经纬度(详细文档) public void getLarLng(String address) throws Exception { String ak = " ...
- 前端学习-使用JS库Leaflet.js生成世界地图并获取标注地址经纬度。
介绍:Leaflet是一个开源的JavaScript库,对移动端友好且对地图有很好的交互性. 大小仅仅只有 33 KB, 同时具有大多数地图所需要的特点. Leaflet设计的非常简单易懂, 同时具有 ...
- 百度地图JavaScript API获取用户当前经纬度和详细地理位置,反之通过详细地理位置获取当前经纬度
前言: 前端时间刚好使用了百度地图的js api定位获取用户当前经纬度并获取当前详细位置和通过当前用户详细地理位置换取用户当前经纬度坐标的功能,为了方便下次找起来方便一些自己在这里记录一下,希望也能够 ...
- 使用百度地图API自动获取地址和经纬度
先上效果图,这是直接点击获取经纬度和地址的.没有做搜索的功能. 代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitiona ...
- java获取https网站证书,附带调用https:webservice接口
一.java 获取https网站证书: 1.创建一个java工程,新建InstallCert类,将以下代码复制进去 package com; import java.io.BufferedReader ...
- java获取图片原始尺寸
java获取图片原始尺寸 URL url = null; InputStream is = null; BufferedImage img = null; try { url = new URL(pi ...
- java学习第13天( java获取当前时间,有关大数据的运算及精确数字运算,Date类)
一 java获取当前时间 学习一个函数,得到当前时间的准确值 System.currectTimeMillis(). 可以得到以毫秒为单位的当前时间.它主要用于计算程序运行时间,long start= ...
- Java获取Web服务器文件
Java获取Web服务器文件 如果获取的是服务器上某个目录下的有关文件,就相对比较容易,可以设定死绝对目录,但是如果不能设定死绝对目录,也不确定web服务器的安装目录,可以考虑如下两种方式: 方法一: ...
- 【java 获取数据库信息】获取MySQL或其他数据库的详细信息
1.首先是 通过数据库获取数据表的详细列信息 package com.sxd.mysqlInfo.test; import java.sql.Connection; import java.sql.D ...
随机推荐
- plink 进行PCA分析
当我们进行群体遗传分析时,得到vcf后,可利用plink进行主成分(PCA)分析: 一.软件安装 1 conda install plink 二.使用流程 第一步:将vcf转换为plink格式 1 p ...
- Perl字符串处理函数用法集锦
Perl字符串处理函数 0.函数名 index 调用语法position=index(string,substring,position); 解说返回子串substring在字符串string中的位置 ...
- 关于写SpringBoot+Mybatisplus+Shiro项目的经验分享二:问题1
框架: SpringBoot+Mybatisplus+Shiro 简单介绍:关于写SpringBoot+Mybatisplus+Shiro项目的经验分享一:简单介绍 添加时,如果失败,不能正确跳转 c ...
- 5 — springboot中的yml多环境配置
1.改文件后缀 2.一张截图搞定多环境编写和切换
- 『学了就忘』Linux文件系统管理 — 65、LVM逻辑卷管理介绍
目录 1.LVM逻辑卷管理的简介 2.LVM逻辑卷管理的原理 3.总结建立LVM分区的步骤 1.LVM逻辑卷管理的简介 LVM是Logical Volume Manager的简称,中文就是逻辑卷管理. ...
- LeetCode 从头到尾打印链表
LeetCode 从头到尾打印链表 题目描述 输入一个链表头节点,从尾到头反过来返回每个节点的值(用数组返回). 示例 1: 输入:head = [1,3,2] 输出:[2,3,1] 一得之见(Jav ...
- 日常Java 2021/10/12
封装 在面向对象程式设计方法中,封装是指-种将抽象性函式接口的实现细节部分包装.隐藏起来的方法 封装可以被认为是一个保护屏障,防止该类的代码和数据被外部类定义的代码随机访问 要访问该类的代码和数据,必 ...
- Output of C++ Program | Set 10
Predict the output of following C++ programs. Question 1 1 #include<iostream> 2 #include<st ...
- Spring Batch : 在不同steps间传递数据
参考文档: How can we share data between the different steps of a Job in Spring Batch? Job Scoped Beans i ...
- vue2 页面路由
vue官方文档 src/views/Login.vue <template> <div> <h2>登录页</h2> </div> </ ...