主流地图 坐标系转换,百度、腾讯、高德等
来源:互联网 发布:js定时器控制动画效果 编辑:程序博客网 时间:2024/05/17 02:00
在我国,为了国家安全,电子地图不可以使用地球坐标系WGS84,必须经过偏转。面前主流的几款地图都有其对应的坐标系。
例如
高德、腾讯、图灵、阿里地图等都是 GCJ-02坐标系(也称火星坐标系)
而百度则使用BD-09坐标系。
那么这3个常用坐标系直接如何转换呢。
参照这个连接我总结了一下。http://blog.csdn.net/meegomeego/article/details/39927017
1,GCJ-02(火星)转BD-09(百度地图)
逻辑:
void bd_encrypt(double gg_lat, double gg_lon, double &bd_lat, double &bd_lon){ double x = gg_lon, y = gg_lat; double z = sqrt(x * x + y * y) + 0.00002 * sin(y * x_pi); double theta = atan2(y, x) + 0.000003 * cos(x * x_pi); bd_lon = z * cos(theta) + 0.0065; bd_lat = z * sin(theta) + 0.006;}
javaScript语法翻译:
function MapabcEncryptToBdmap(gg_lat, gg_lon) { var point=new Object(); var x_pi = 3.14159265358979324 * 3000.0 / 180.0; var x = new Number(gg_lon); var y = new Number(gg_lat); var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi); var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi); var bd_lon = z * Math.cos(theta) + 0.0065; var bd_lat = z * Math.sin(theta) + 0.006; point.lng=bd_lon; point.lat=bd_lat; //alert("-1:"+point.lng+","+point.lat); return point; }
2,BD-09(百度地图)转 GCJ-02(火星)
逻辑:
void bd_decrypt(double bd_lat, double bd_lon, double &gg_lat, double &gg_lon){ double x = bd_lon - 0.0065, y = bd_lat - 0.006; double z = sqrt(x * x + y * y) - 0.00002 * sin(y * x_pi); double theta = atan2(y, x) - 0.000003 * cos(x * x_pi); gg_lon = z * cos(theta); gg_lat = z * sin(theta);}
javaScript语法翻译
function BdmapEncryptToMapabc(bd_lat,bd_lon) { var point=new Object(); var x_pi = 3.14159265358979324 * 3000.0 / 180.0; var x = new Number(bd_lon - 0.0065); var y = new Number(bd_lat - 0.006); var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi); var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi); var Mars_lon = z * Math.cos(theta); var Mars_lat = z * Math.sin(theta); point.lng=Mars_lon; point.lat=Mars_lat; return point; }
3,WGS84(地球坐标系)转BD-09(百度坐标系)
function GPSToBaidu(lngX,latY){var gps_point=new BMap.Point(lngX,latY);BMap.Convertor.translate(gps_point,0,function(bd_point){ alert("lng:"+bd_point.lng+" lat:"+bd_point.lat);});}
4,WGS84(地球坐标系)转GCJ-02(火星坐标系)
逻辑C#版(干活了,没时间了):
using System;namespace Navi{ class EvilTransform { const double pi = 3.14159265358979324; // // Krasovsky 1940 // // a = 6378245.0, 1/f = 298.3 // b = a * (1 - f) // ee = (a^2 - b^2) / a^2; const double a = 6378245.0; const double ee = 0.00669342162296594323; // // World Geodetic System ==> Mars Geodetic System public static void transform(double wgLat, double wgLon, out double mgLat, out double mgLon) { if (outOfChina(wgLat, wgLon)) { mgLat = wgLat; mgLon = wgLon; return; } double dLat = transformLat(wgLon - 105.0, wgLat - 35.0); double dLon = transformLon(wgLon - 105.0, wgLat - 35.0); double radLat = wgLat / 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); mgLat = wgLat + dLat; mgLon = wgLon + dLon; } static bool 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; } 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; } 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; } }}
关于准确性,BD-09和GCJ-02我验证过了,误差在10米左右,可以接收。WGS-84和其他坐标系直接的转换待完善和验证。
0 0
- 主流地图 坐标系转换,百度、腾讯、高德等
- 百度高德地图 坐标系转换
- 高德,百度,Google地图定位偏移以及坐标系转换
- 高德,百度,Google地图定位偏移以及坐标系转换
- 高德,百度,Google地图定位偏移以及坐标系转换
- 高德,百度,Google地图定位偏移以及坐标系转换
- 高德,百度,Google地图定位偏移以及坐标系转换
- 高德,百度,Google地图定位偏移以及坐标系转换
- 高德,百度,Google地图定位偏移以及坐标系转换
- 国内地图坐标系介绍及常见地图(百度、高德、凯立德)之间的坐标系转换
- 国内地图坐标系介绍及常见地图(百度、高德、凯立德)之间的坐标系转换
- 坐标系,硬件/谷歌地球卫星 谷歌地图 百度地图 腾讯地图/高德地图 图吧地图
- 百度、搜狗、高德、腾讯等地图完美处理偏移
- 高德地图,百度地图等坐标体系,坐标转换
- 关于百度地图和高德地图,关于地图坐标系
- 百度地图和高德地图,关于地图坐标系
- 高德百度坐标系转换方法
- 高德百度坐标系转换方法
- 内存对齐
- sql2008评估已过期问题
- DHCP
- 【LeetCode】Container With Most Water 解题报告
- Hadoop大象之旅007-配置Hadoop伪分布模式
- 主流地图 坐标系转换,百度、腾讯、高德等
- php读书笔记
- 成长就是一种磨练
- 查看Eclipse版本号及各个版本区别
- Android中eclipse等常用工具软件下载
- 《Java7程序设计》第24章 并发工具
- NYOJ 260、263、264
- Windows静态库和动态库的创建和使用
- BestCoder Round #20 B,C