mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
add test
This commit is contained in:
parent
cffb294bfe
commit
88edbafe4b
@ -111,7 +111,7 @@ public class CoordinateUtil {
|
||||
* @param lat 纬度值
|
||||
* @return GCJ-02 坐标
|
||||
*/
|
||||
public static Coordinate bd09toGcj02(double lng, double lat) {
|
||||
public static Coordinate bd09ToGcj02(double lng, double lat) {
|
||||
double x = lng - 0.0065;
|
||||
double y = lat - 0.006;
|
||||
double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI);
|
||||
@ -129,7 +129,7 @@ public class CoordinateUtil {
|
||||
* @return WGS84坐标
|
||||
*/
|
||||
public static Coordinate bd09toWgs84(double lng, double lat) {
|
||||
final Coordinate gcj02 = bd09toGcj02(lng, lat);
|
||||
final Coordinate gcj02 = bd09ToGcj02(lng, lat);
|
||||
return gcj02ToWgs84(gcj02.lng, gcj02.lat);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,47 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 坐标转换工具类单元测试<br>
|
||||
* 测试参考:https://github.com/wandergis/coordtransform
|
||||
*
|
||||
* @author hongzhe.qin, looly
|
||||
*/
|
||||
public class CoordinateUtilTest {
|
||||
|
||||
@Test
|
||||
public void gcj02ToBd09Test() {
|
||||
final CoordinateUtil.Coordinate gcj02 = CoordinateUtil.gcj02ToBd09(116.404, 39.915);
|
||||
Assert.assertEquals(116.41036949371029D, gcj02.getLng(), 15);
|
||||
Assert.assertEquals(39.92133699351021D, gcj02.getLat(), 15);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bd09toGcj02Test(){
|
||||
final CoordinateUtil.Coordinate gcj02 = CoordinateUtil.bd09ToGcj02(116.404, 39.915);
|
||||
Assert.assertEquals(116.39762729119315D, gcj02.getLng(), 15);
|
||||
Assert.assertEquals(39.90865673957631D, gcj02.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(){
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
package cn.hutool.core.util;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* 坐标转换工具类单元测试
|
||||
*
|
||||
* ps: 坐标转换存在一定误差,故此工具类无单元测试,无法验证,请根据实际业务判断误差值
|
||||
*
|
||||
* @author hongzhe.qin
|
||||
*/
|
||||
public class W84UtilTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void gcj02tobd09Test() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void bd09togcj02(){
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gcj02towgs84(){
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wgs84togcj02(){
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wgs84tobd09(){
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user