对接VMS系统出现了经纬度处理不一致的问题,我们数据库保存经纬度是根据不同的订单类型保存的,有的是百度经纬度值,有的存的是腾讯经纬度值.但是经纬度的坐标系都是国标,VMS接口的处理是按照腾讯经纬度处理的。以下是经纬度转化的工具类:
package com.nio.dms.web.service.commons;
import java.util.HashMap;
import java.util.Map;
/**
* 坐标系转换 ,腾讯坐标转 百度,百度转腾讯
*
*/
public class TransferOfMap {
private static final double xPi = 3.14159265358979324 * 3000.0 / 180.0;
/**
* 返回百度坐标
* @param tencentMap
* @return
*/
public static Map<String,Double> bdEncrypt(String lon,String lan)
{
double x = Double.valueOf(lon), y = Double.valueOf(lan);
double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * xPi);
double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * xPi);
double bdLon = z * Math.cos(theta) + 0.0065;
double bdLat = z * Math.sin(theta) + 0.006;
Map<String,Double> baiduMap = new HashMap<String,Double>();
baiduMap.put("lon", bdLon);
baiduMap.put("lat", bdLat);
return baiduMap;
}
/**
* 返回腾讯坐标
* @param tencentMap
*/
public static Map<String,Double> bdDecrypt(String lon,String lan){
double x = Double.valueOf(lon) - 0.0065, y = Double.valueOf(lan) - 0.006;
double z =Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * xPi);
double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * xPi);
double ggLon = z * Math.cos(theta);
double ggLat = z * Math.sin(theta);
Map<String,Double> bdMap = new HashMap<String,Double>();
bdMap.put("lon", ggLon);
bdMap.put("lat", ggLat);
return bdMap;
}
}