JSP 火星坐标及GPS坐标 转百度坐标


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); 
}  
  


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坐标转百度坐标



<!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>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值