JSP 火星坐标及GPS坐标 转百度坐标
来源:互联网 发布:淘宝商城充气姓娃好吗 编辑:程序博客网 时间:2024/06/11 11:03
转自: http://blog.csdn.net/ma969070578/article/details/38257691
1、火星坐标系 (GCJ-02) 与百度坐标系 (BD-09) 的转换算法
关于 GCJ-02 和 BD-09 ,请参考 http://developer.baidu.com/map/question.htm#qa0043 。
算法代码如下,其中 bd_encrypt
将 GCJ-02 坐标转换成 BD-09 坐标, bd_decrypt
反之。
#include <math.h>
const double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
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);
}
const double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
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);
}
jsp:
var x_pi = 52.35987755982988;
function bd_encrypt(gg_lat, gg_lon)
{
var x = gg_lon, y = 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);
bd_lon = z * Math.cos(theta) + 0.0065;
bd_lat = z * Math.sin(theta) + 0.006;
// alert("x"+bd_lon);
// alert("y"+bd_lat);
var point = new BMap.Point(bd_lon, bd_lat);
return point;
}
2、GPS坐标转百度坐标
参考:http://developer.baidu.com/map/jsdemo.htm#a5_2
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
- <style type="text/css">
- body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
- </style>
- <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=idpDDCCenuVQ3y5eD9xU1BM4"></script>
- <script type="text/javascript" src="http://developer.baidu.com/map/jsdemo/demo/convertor.js"></script>
- <title>GPS转百度</title>
- </head>
- <body>
- <div id="allmap"></div>
- </body>
- </html>
- <script type="text/javascript">
- // 百度地图API功能
- //GPS坐标
- var xx = 116.397428;
- var yy = 39.90923;
- var gpsPoint = new BMap.Point(xx,yy);
- //地图初始化
- var bm = new BMap.Map("allmap");
- bm.centerAndZoom(gpsPoint, 15);
- bm.addControl(new BMap.NavigationControl());
- bm.enableScrollWheelZoom();
- //添加谷歌marker和label
- var markergps = new BMap.Marker(gpsPoint);
- bm.addOverlay(markergps); //添加GPS标注
- var labelgps = new BMap.Label("GPS",{offset:new BMap.Size(20,-10)});
- markergps.setLabel(labelgps); //添加GPS标注
- //坐标转换完之后的回调函数
- translateCallback = function (point){
- var marker = new BMap.Marker(point);
- bm.addOverlay(marker);
- var label = new BMap.Label("111111",{offset:new BMap.Size(40,-10)});
- marker.setLabel(label); //添加百度label
- bm.setCenter(point);
- alert(point.lng + "," + point.lat);
- }
- for(var i =0 ;i<3;i++){
- var xx = 116.397428 + i*5;
- var yy = 39.90923+i*5;
- var gpsPoint22 = new BMap.Point(xx,yy);
- BMap.Convertor.translate(gpsPoint22,0,translateCallback); //真实经纬度转成百度坐标
- }
- </script>
0 0
- JSP 火星坐标及GPS坐标 转百度坐标
- JSP 火星坐标及GPS坐标 转百度坐标
- gps坐标转火星坐标
- 百度坐标转火星坐标
- 火星坐标转百度坐标
- 火星坐标转百度坐标
- java版坐标系转换(火星坐标、GPS坐标、百度坐标)
- GPS坐标转换成百度坐标和火星坐标
- 百度坐标(bd0911)互转火星坐标(gcj02)和国测局坐标(GPS)
- iOS地球坐标,火星坐标,百度坐标互转
- iOS地球坐标,火星坐标,百度坐标互转
- iOS地球坐标,火星坐标,百度坐标互转
- iOS地球坐标,火星坐标,百度坐标互转
- 地球坐标,火星坐标,百度坐标转换
- 地球坐标,火星坐标,百度坐标转换
- 地球坐标,火星坐标,百度坐标转换
- 地球坐标,火星坐标,百度坐标转换
- 地球坐标,火星坐标,百度坐标转换
- 大数据相加(转载)
- aop切入点表达式
- Container With Most Water
- 简单的sql查询优化
- wampserver提示You don't have permission to access / on this server
- JSP 火星坐标及GPS坐标 转百度坐标
- Maven根据现有项目自定义archetype
- 哲学家就餐问题
- nscalendar
- ORA-12154: TNS: 无法解析指定的连接标识符
- 自动装箱/拆箱,以及高速缓存问题
- 关于Git合并分支并删除分支后的恢复
- javascript this详解 面向对象
- hdu 2852 KiKi's K-Number