火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法
2015-10-13 16:54
387 查看
const double x_pi = 3.14159265358979324 * 3000.0 / 180.0; //火星坐标系 (GCJ-02) 转换 百度坐标系 (BD-09) + (CLLocationCoordinate2D)convertToBaiduCoordinate:(CLLocationCoordinate2D)gcjCoordinate { double x = gcjCoordinate.longitude; double y = gcjCoordinate.latitude; double z = sqrt(x * x + y * y) + 0.00002 * sin(y * x_pi); double theta = atan2(y, x) + 0.000003 * cos(x * x_pi); double bd_lon = z * cos(theta) + 0.0065; double bd_lat = z * sin(theta) + 0.006; NSLog(@"%f, %f", bd_lon, bd_lat); return CLLocationCoordinate2DMake(bd_lat, bd_lon); } //百度坐标系 (BD-09) 转换 火星坐标系 (GCJ-02) + (CLLocationCoordinate2D)convertToGCJCoordinate:(CLLocationCoordinate2D)baiduCoordinate { double x = baiduCoordinate.longitude - 0.0065; double y = baiduCoordinate.latitude - 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); double gg_lon = z * cos(theta); double gg_lat = z * sin(theta); NSLog(@"%f, %f", gg_lon, gg_lat); return CLLocationCoordinate2DMake(gg_lat, gg_lon); }
不过也有更简单的算法,线性算法(lat和lng是经纬度,球面坐标):
To_B是转到百度,To_G是转到GCJ-02。
var TO_BLNG = function(lng){return lng+0.0065;};
var TO_BLAT = function(lat){return lat+0.0060;};
var TO_GLNG = function(lng){return lng-0.0065;};
var TO_GLAT = function(lat){return lat-0.0060;};
相关文章推荐
- java中的包package
- 阿里云 购买与部署: 流程拾遗
- Mysql 之 视图
- Oracle中关于处理小数点位数的几个函数,取小数位数,Oracle查询函数
- Android Studio导入项目的几种方法
- Excel的最大行数
- 在这里给博客园的朋友们说抱歉了!
- ***5.33-当前日期与时间
- HttpsURLConnection访问HTTPS链接时信任所有证书
- Larazus开发计算器
- crmjs脚步获取服务器时间
- 猴子选大王 php
- python多线程编程(二)--threading模块
- Flume1.5.0的安装、部署、简单应用(含伪分布式、与hadoop2.2.0、hbase0.96的案例)
- 设置文本字体大小
- JS中A标签模拟POST请求
- PHP图片处理---画各种图像
- ZOJ 1649 Rescue(BFS)
- #!/bin/bash
- SVN无法提交代码或者代码被锁定