引用Eclipse在github上的一个开源项目https://github.com/locationtech/proj4j
1. pom.xml引入依赖
<!-- https://mvnrepository.com/artifact/org.locationtech.proj4j/proj4j -->
<dependency>
<groupId>org.locationtech.proj4j</groupId>
<artifactId>proj4j</artifactId>
<version>1.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.locationtech.proj4j/proj4j-epsg -->
<dependency>
<groupId>org.locationtech.proj4j</groupId>
<artifactId>proj4j-epsg</artifactId>
<version>1.3.0</version>
</dependency>
2. 转换工具类定义
// 导包
import org.locationtech.proj4j.*;
// 工具类定义
public class CoordinatesUtil {
/**
* WGS84->2000国家大地坐标系(CGCS2000)
*
* @param longitude WGS84经度值
* @param latitude WGS84纬度值
* @return x,y CGCS2000经度值,CGCS2000纬度值
*/
public static String WGS84ToCGCS2000(double longitude, double latitude) {
CRSFactory crsFactory = new CRSFactory();
CoordinateReferenceSystem WGS84 = crsFactory.createFromName("epsg:4326");
// 根据经度范围确定转换标准,具体EPSG定义参考https://epsg.io
String degree3EPSG = "epsg:4528";
if (longitude < 76.3) {
// CGCS2000 / 3-degree Gauss-Kruger zone 25
degree3EPSG = "epsg:4513";
} else if (longitude >= 76.3 && longitude < 79.3) {
// CGCS2000 / 3-degree Gauss-Kruger zone 26
degree3EPSG = "epsg:4514";
} else if (longitude >= 79.3 && longitude < 82.3) {
// CGCS2000 / 3-degree Gauss-Kruger zone 27
degree3EPSG = "epsg:4515";
} else if (longitude >=