请给我一个java写的BD09转GCJ02坐标系的代码
时间: 2024-04-10 12:34:27 浏览: 97
当然,下面是一个使用Java编写的BD09转GCJ02坐标系的代码示例:
```java
import java.math.BigDecimal;
public class CoordinateConverter {
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;
public static Point convertBD09ToGCJ02(double bdLat, double bdLng) {
double x = bdLng - 0.0065;
double y = bdLat - 0.006;
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_PI);
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_PI);
double ggLng = z * Math.cos(theta);
double ggLat = z * Math.sin(theta);
return new Point(ggLat, ggLng);
}
public static class Point {
private final double latitude;
private final double longitude;
public Point(double latitude, double longitude) {
this.latitude = latitude;
this.longitude = longitude;
}
public double getLatitude() {
return latitude;
}
public double getLongitude() {
return longitude;
}
}
}
```
你可以使用上面的代码将BD09坐标系的经纬度转换为GCJ02坐标系的经纬度。使用方法如下:
```java
double bdLat = 39.908723;
double bdLng = 116.397496;
CoordinateConverter.Point point = CoordinateConverter.convertBD09ToGCJ02(bdLat, bdLng);
System.out.println("GCJ02坐标系:");
System.out.println("Latitude: " + point.getLatitude());
System.out.println("Longitude: " + point.getLongitude());
```
请注意,这段代码仅提供了BD09到GCJ02的转换,如果你需要其他坐标系的转换,你可能需要查找相应的算法或库。
阅读全文