坐标系统:用于定位的系统,就跟二维笛卡尔坐标系统一样,一个点使用(x,y),就能确定该点在笛卡尔坐标系统中的唯一位置。这里讲的坐标系统,相对于笛卡尔坐标系统,要复杂许多,但作用却都是一样,主要用于定位,也就是精确地定位地表上的一点。
地理坐标系统:WGS84就是一种地理坐标系统。地理坐标坐标是对地球进行简单几何建模,比如将地球看成一个球体或者类球体,然后再将地表上点投影到该球面上形成的坐标就是地理坐标系统。WGS84就是定义了如何将地球抽象成球体或者类球体的规则。或者简单地来说,WGS84就是一堆参数,用于建立球体或者类球体,来近似地球。
投影坐标系统:由于地球是一个球状,所以一般将其某个区域投影在平面上,形成的坐标系称为投影坐标系。
WGS84 :地理坐标系统,Google Earth和中国外的Google Map使用,另外,目前基本上所有定位空间位置的设备都使用这种坐标系统,例如手机的GPS系统。
GCJ-02:投影坐标系统,也就是我们平常所说的火星坐标系,Google Map中国、高德和腾讯好像使用,这个是中国自己在WGS84基础上加密而成,目的显而易见。
BD09:投影坐标系统,百度地图使用,在GCJ-02基础上二次加密而成。
- 可以通过嗲用直接的算法来转换
- 可以通过Web API来转换
- 可以通过第三方SDK API来转换
public static String bMapTransqqMap(double lat, double lon){ double txLat; double txLon; double xPi=3.14159265358979324; double x = lon - 0.0065, y = lat - 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); txLon = z * Math.cos(theta); txLat = z * Math.sin(theta); return txLat+","+txLon; } public static Double[] qqMapTransBmap(double lat, double lon){ double bdLat; double bdLon; double xPi=3.14159265358979324; double x = lon, y = lat; 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); bdLon = z * Math.cos(theta) + 0.0065; bdLat = z * Math.sin(theta) + 0.006; Double[] result = {bdLat,bdLon}; return result; }更多转换算法 GPS.java
public class GPS { private double lat; private double lon; public GPS(double lat, double lon) { this.lat = lat; this.lon = lon; } public double getLat() { return lat; } public void setLat(double lat) { this.lat = lat; } public double getLon() { return lon; } public void setLon(double lon) { this.lon = lon; } public String toString() { return "lat:" + lat + "," + "lon:" + lon; } }GPSConverterUtils.java
public class GPSConverterUtils { public static final String BAIDU_LBS_TYPE = "bd09ll"; public static double pi = 3.1415926535897932384626; public static double a = 6378245.0; public static double ee = 0.00669342162296594323; public static GPS gps84_To_Gcj02(double lat, double lon) { if (outOfChina(lat, lon)) { return null; } double dLat = transformLat(lon - 105.0, lat - 35.0); double dLon = transformLon(lon - 105.0, lat - 35.0); double radLat = lat / 180.0 * pi; double magic = Math.sin(radLat); magic = 1 - ee * magic * magic; double sqrtMagic = Math.sqrt(magic); dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi); double mgLat = lat + dLat; double mgLon = lon + dLon; return new GPS(mgLat, mgLon); } public static GPS gcj_To_Gps84(double lat, double lon) { GPS gps = transform(lat, lon); double lontitude = lon * 2 - gps.getLon(); double latitude = lat * 2 - gps.getLat(); return new GPS(latitude, lontitude); } public static GPS gcj02_To_Bd09(double gg_lat, double gg_lon) { double x = gg_lon, y = gg_lat; double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * pi); double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * pi); double bd_lon = z * Math.cos(theta) + 0.0065; double bd_lat = z * Math.sin(theta) + 0.006; return new GPS(bd_lat, bd_lon); } public static GPS bd09_To_Gcj02(double bd_lat, double bd_lon) { double x = bd_lon - 0.0065, y = bd_lat - 0.006; double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * pi); double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * pi); double gg_lon = z * Math.cos(theta); double gg_lat = z * Math.sin(theta); return new GPS(gg_lat, gg_lon); } public static GPS bd09_To_Gps84(double bd_lat, double bd_lon) { GPS gcj02 = bd09_To_Gcj02(bd_lat, bd_lon); GPS map84 = gcj_To_Gps84(gcj02.getLat(), gcj02.getLon()); return map84; } public static boolean outOfChina(double lat, double lon) { if (lon < 72.004 || lon > 137.8347) return true; if (lat < 0.8293 || lat > 55.8271) return true; return false; } public static GPS transform(double lat, double lon) { if (outOfChina(lat, lon)) { return new GPS(lat, lon); } double dLat = transformLat(lon - 105.0, lat - 35.0); double dLon = transformLon(lon - 105.0, lat - 35.0); double radLat = lat / 180.0 * pi; double magic = Math.sin(radLat); magic = 1 - ee * magic * magic; double sqrtMagic = Math.sqrt(magic); dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi); dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi); double mgLat = lat + dLat; double mgLon = lon + dLon; return new GPS(mgLat, mgLon); } public static double transformLat(double x, double y) { double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x)); ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0; ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0; ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0; return ret; } public static double transformLon(double x, double y) { double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x)); ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0; ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0; ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0; return ret; } }资料参考:
https://www.jianshu.com/p/c39a2c72dc65?from=singlemessage
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)