您的位置:首页 > 其它

火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法

2013-12-27 10:35 330 查看
关于 GCJ-02 和 BD-09 ,请参考 http://developer.baidu.com/map/question.htm#qa0043

算法代码如下,其中
bd_encrypt
将 GCJ-02 坐标转换成 BD-09 坐标,
bd_decrypt
反之。

01
#include
<math.h>
02
 
03
const
double
x_pi
= 3.14159265358979324 * 3000.0 / 180.0;
04
 
05
void
bd_encrypt(
double
gg_lat,
double
gg_lon,
double
&bd_lat,
double
&bd_lon)
06
{
07
double
x
= gg_lon,y = gg_lat;
08
double
z
=
sqrt
(x
* x + y * y) + 0.00002 *
sin
(y
* x_pi);
09
double
theta
=
atan2
(y,
x) + 0.000003 *
cos
(x
* x_pi);
10
bd_lon
= z *
cos
(theta)
+ 0.0065;
11
bd_lat
= z *
sin
(theta)
+ 0.006;
12
}
13
 
14
void
bd_decrypt(
double
bd_lat,
double
bd_lon,
double
&gg_lat,
double
&gg_lon)
15
{
16
double
x
= bd_lon - 0.0065, y = bd_lat - 0.006;
17
double
z
=
sqrt
(x
* x + y * y) - 0.00002 *
sin
(y
* x_pi);
18
double
theta
=
atan2
(y,
x) - 0.000003 *
cos
(x
* x_pi);
19
gg_lon
= z *
cos
(theta);
20
gg_lat
= z *
sin
(theta);
21
}
需要php版本的可以自己对照着写一下,很简单的!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: