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

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

你可能感兴趣的:(gps,地图,坐标,纠偏)