mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix bug
This commit is contained in:
parent
aeffe6a545
commit
7ac58bc4d8
@ -22,12 +22,12 @@ public class CoordinateUtil {
|
|||||||
/**
|
/**
|
||||||
* 坐标转换参数:(火星坐标系与百度坐标系转换的中间量)
|
* 坐标转换参数:(火星坐标系与百度坐标系转换的中间量)
|
||||||
*/
|
*/
|
||||||
public static final double X_PI = 3.14159265358979324 * 3000.0 / 180.0;
|
public static final double X_PI = 3.1415926535897932384626433832795 * 3000.0 / 180.0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 坐标转换参数:π
|
* 坐标转换参数:π
|
||||||
*/
|
*/
|
||||||
public static final double PI = 3.1415926535897932384626D;
|
public static final double PI = 3.1415926535897932384626433832795D;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 地球半径(Krasovsky 1940)
|
* 地球半径(Krasovsky 1940)
|
||||||
@ -167,7 +167,7 @@ public class CoordinateUtil {
|
|||||||
dlng = (dlng * 180.0) / (RADIUS / sqrtMagic * Math.cos(lat / 180.0 * PI) * PI);
|
dlng = (dlng * 180.0) / (RADIUS / sqrtMagic * Math.cos(lat / 180.0 * PI) * PI);
|
||||||
dlat = (dlat * 180.0) / ((RADIUS * (1 - CORRECTION_PARAM)) / (magic * sqrtMagic) * PI);
|
dlat = (dlat * 180.0) / ((RADIUS * (1 - CORRECTION_PARAM)) / (magic * sqrtMagic) * PI);
|
||||||
|
|
||||||
if(false == isPlus){
|
if(!isPlus){
|
||||||
dlng = - dlng;
|
dlng = - dlng;
|
||||||
dlat = - dlat;
|
dlat = - dlat;
|
||||||
}
|
}
|
||||||
@ -280,7 +280,7 @@ public class CoordinateUtil {
|
|||||||
*/
|
*/
|
||||||
public Coordinate offset(Coordinate offset){
|
public Coordinate offset(Coordinate offset){
|
||||||
this.lng += offset.lng;
|
this.lng += offset.lng;
|
||||||
this.lat += offset.lng;
|
this.lat += offset.lat;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,37 +11,46 @@ import org.junit.Test;
|
|||||||
*/
|
*/
|
||||||
public class CoordinateUtilTest {
|
public class CoordinateUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void wgs84ToGcj02Test(){
|
||||||
|
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.wgs84ToGcj02(116.404, 39.915);
|
||||||
|
Assert.assertEquals(116.41033392216508D, coordinate.getLng(), 15);
|
||||||
|
Assert.assertEquals(39.91640428150164D, coordinate.getLat(), 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void gcj02ToWgs84Test(){
|
||||||
|
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.gcj02ToWgs84(116.404, 39.915);
|
||||||
|
Assert.assertEquals(116.39766607783491D, coordinate.getLng(), 15);
|
||||||
|
Assert.assertEquals(39.91359571849836D, coordinate.getLat(), 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void wgs84toBd09Test(){
|
||||||
|
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.wgs84ToBd09(116.404, 39.915);
|
||||||
|
Assert.assertEquals(116.41671695444782D, coordinate.getLng(), 15);
|
||||||
|
Assert.assertEquals(39.922698713521726D, coordinate.getLat(), 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bd09toWgs84Test(){
|
||||||
|
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.bd09toWgs84(116.404, 39.915);
|
||||||
|
Assert.assertEquals(116.39129143419822D, coordinate.getLng(), 15);
|
||||||
|
Assert.assertEquals(39.907253214522164D, coordinate.getLat(), 15);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void gcj02ToBd09Test() {
|
public void gcj02ToBd09Test() {
|
||||||
final CoordinateUtil.Coordinate gcj02 = CoordinateUtil.gcj02ToBd09(116.404, 39.915);
|
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.gcj02ToBd09(116.404, 39.915);
|
||||||
Assert.assertEquals(116.41036949371029D, gcj02.getLng(), 15);
|
Assert.assertEquals(116.41036949371029D, coordinate.getLng(), 15);
|
||||||
Assert.assertEquals(39.92133699351021D, gcj02.getLat(), 15);
|
Assert.assertEquals(39.92133699351022D, coordinate.getLat(), 15);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bd09toGcj02Test(){
|
public void bd09toGcj02Test(){
|
||||||
final CoordinateUtil.Coordinate gcj02 = CoordinateUtil.bd09ToGcj02(116.404, 39.915);
|
final CoordinateUtil.Coordinate coordinate = CoordinateUtil.bd09ToGcj02(116.404, 39.915);
|
||||||
Assert.assertEquals(116.39762729119315D, gcj02.getLng(), 15);
|
Assert.assertEquals(116.39762729119315D, coordinate.getLng(), 15);
|
||||||
Assert.assertEquals(39.90865673957631D, gcj02.getLat(), 15);
|
Assert.assertEquals(39.90865673957631D, coordinate.getLat(), 15);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void gcj02ToWgs84(){
|
|
||||||
final CoordinateUtil.Coordinate gcj02 = CoordinateUtil.wgs84ToGcj02(116.404, 39.915);
|
|
||||||
Assert.assertEquals(116.39775550083061D, gcj02.getLng(), 15);
|
|
||||||
Assert.assertEquals(39.91359571849836D, gcj02.getLat(), 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void wgs84ToGcj02Test(){
|
|
||||||
final CoordinateUtil.Coordinate gcj02 = CoordinateUtil.wgs84ToGcj02(116.404, 39.915);
|
|
||||||
Assert.assertEquals(116.41024449916938D, gcj02.getLng(), 15);
|
|
||||||
Assert.assertEquals(39.91640428150164D, gcj02.getLat(), 15);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void wgs84toBd09(){
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user