package com.moral.util; import com.moral.service.impl.DeviceServiceImpl; import org.apache.log4j.Logger; import java.util.ArrayList; import java.util.List; public class LatLngTransformation { private static final double x_pi = 3.14159265358979324 * 3000.0 / 180.0; private static Logger log = Logger.getLogger(LatLngTransformation.class); /// /// 中国正常坐标系 GCJ02 协议的坐标,转到百度地图对应的 BD09 协议坐标 /// /// 维度 /// 经度 public static List Convert_GCJ02_To_BD09(double lat, double lng) { List list=new ArrayList(); double x = lng, y = lat; 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); lng = z * Math.cos(theta) + 0.0065; lat = z * Math.sin(theta) + 0.006; list.add(lng); list.add(lat); return list; } /// /// 百度地图对应的 BD09 协议坐标,转到 中国正常坐标系 GCJ02 协议的坐标 /// /// 维度 /// 经度 public static List Convert_BD09_To_GCJ02(double lat,double lng) { List list=new ArrayList(); double x = lng - 0.0065, y = lat - 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); lng = z * Math.cos(theta); lat = z * Math.sin(theta); list.add(lng); list.add(lat); return list; } }