地图坐标纠偏及投影转换的常见算法

Web墨卡托坐标与WGS84坐标互转

//经纬度转墨卡托
-(CGPoint )lonLat2Mercator:(CGPoint ) lonLat
{
    CGPoint  mercator;
    double x = lonLat.x *20037508.34/180;
    double y = log(tan((90+lonLat.y)*M_PI/360))/(M_PI/180);
    y = y *20037508.34/180;
    mercator.x = x;
    mercator.y = y;
    return mercator ;
}
//墨卡托转经纬度
-(CGPoint )Mercator2lonLat:(CGPoint ) mercator
{
    CGPoint lonLat;
    double x = mercator.x/20037508.34*180;
    double y = mercator.y/20037508.34*180;
    y= 180/M_PI*(2*atan(exp(y*M_PI/180))-M_PI/2);
    lonLat.x = x;
    lonLat.y = y;
    return lonLat;
}

火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 互转

#include <math.h>  
  
const double x_pi = 3.14159265358979324 * 3000.0 / 180.0;  
//将 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;  
}  
  
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);  
}  

简单算法(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;};


各家公众地图坐标体系:http://www.cnblogs.com/milkmap/p/3768379.html


GPS转换为GCJ-02坐标

https://www.google.com.hk/search?q=wgtochina_lb&hl=zh-CN


参考资料:

  1. http://bbs.esrichina-bj.cn/esri/viewthread.php?tid=78245
  2. http://blog.csdn.net/coolypf/article/details/8569813
  3. http://www.cnblogs.com/milkmap/p/3627940.html
  4. http://www.cnblogs.com/milkmap/p/3768379.html

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值