JSP 火星坐标及GPS坐标 转百度坐标
2015-06-04 15:41
811 查看
转自: http://blog.csdn.net/ma969070578/article/details/38257691
关于 GCJ-02 和 BD-09 ,请参考 http://developer.baidu.com/map/question.htm#qa0043 。
算法代码如下,其中
#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)
[align=left]{ [/align]
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);
[align=left] bd_lon = z * Math.cos(theta) + 0.0065; [/align]
[align=left] bd_lat = z * Math.sin(theta) + 0.006;[/align]
[align=left] [/align]
//
alert("x"+bd_lon);
//
alert("y"+bd_lat);
var point
= new BMap.Point(bd_lon,
bd_lat);
[align=left] return point;[/align]
[align=left]} [/align]
[javascript] view
plaincopy
<!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>
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);
}
var x_pi
= 52.35987755982988;
function bd_encrypt(gg_lat,
gg_lon)
[align=left]{ [/align]
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);
[align=left] bd_lon = z * Math.cos(theta) + 0.0065; [/align]
[align=left] bd_lat = z * Math.sin(theta) + 0.006;[/align]
[align=left] [/align]
//
alert("x"+bd_lon);
//
alert("y"+bd_lat);
var point
= new BMap.Point(bd_lon,
bd_lat);
[align=left] return point;[/align]
[align=left]} [/align]
2、GPS坐标转百度坐标
参考:http://developer.baidu.com/map/jsdemo.htm#a5_2[javascript] view
plaincopy
<!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>
相关文章推荐
- js日期时间函数(经典+完善+实用)
- 201506041201_《JavaScript权威指南》(p64-90)
- 添加、修改弹出框的退格键禁用
- list转换json
- JavaScript 命名函数与匿名函数
- jstl的formatNumber标签的四舍五入问题
- js字符串全部替换
- js 判断数组中是否包含
- JavaScript基础
- js封装
- JavaScript脑筋急转弯
- JSTL遍历数组,List,Set,Map等
- JSF扩展插件之prettyFaces
- D3学习之:D3.js中的12中地图投影方式
- js mouseover连续触发
- JavaScript语言技巧
- Javascript创建类的七种方法
- JavaScript 框架比较
- WP runtime post 请求, json 解析
- C#实现json的序列化和反序列化