系数未经大量测试,少量测试是可用的,但是也已经在生产环境中实际使用,没有发现什么问题。
经度 lon=116.32715863448607
纬度 lat=39.990912172420714
一、假定基础坐标为谷歌坐标,转为百度坐标
0 1 2 3 |
// coeff_lon=0.00661275189627 // coeff_lat=0.00573347020969 lon_new=lon+coeff_lon lat_new=lat+coeff_lat |
二、假定基础坐标为GPS原始坐标,转为百度坐标
0 1 2 3 |
// coeff_lon=0.0127793111931 // coeff_lat=0.00699604707901 lon_new=lon+coeff_lon lat_new=lat+coeff_lat |
下图A点是转换前坐标位置,B点是把A作为谷歌坐标转换成百度坐标,C点是把A作为GPS坐标转换为百度坐标。
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
<!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;font-family:"微软雅黑";} </style> <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=您的密钥"></script> <title>google/GPS原始坐标转百度</title> </head> <body> <div id="allmap"></div> </body> </html> <script type="text/javascript"> // 百度地图API功能 //谷歌坐标 var x = 116.32715863448607; var y = 39.990912172420714; var ggPoint = new BMap.Point(x,y); //地图初始化 var bm = new BMap.Map("allmap"); bm.centerAndZoom(ggPoint, 15); bm.addControl(new BMap.NavigationControl()); //添加谷歌marker和label var markergg = new BMap.Marker(ggPoint); bm.addOverlay(markergg); //添加谷歌marker var labelgg = new BMap.Label("A:谷歌/GPS(错误)",{offset:new BMap.Size(20,-10)}); markergg.setLabel(labelgg); //添加谷歌label //坐标转换完之后的回调函数 translateCallback = function (data){ if(data.status === 0) { var marker = new BMap.Marker(data.points[0]); console.log('谷歌转百度',marker.point); bm.addOverlay(marker); var label = new BMap.Label("B:谷歌转百度(正确)",{offset:new BMap.Size(20,-10)}); marker.setLabel(label); //添加百度label bm.setCenter(data.points[0]); } } //坐标转换完之后的回调函数 translateCallback2 = function (data){ if(data.status === 0) { var marker = new BMap.Marker(data.points[0]); console.log('GPS转百度',marker.point); bm.addOverlay(marker); var label = new BMap.Label("C:GPS转百度(正确2)",{offset:new BMap.Size(20,-10)}); marker.setLabel(label); //添加百度label bm.setCenter(data.points[0]); } } setTimeout(function(){ var convertor = new BMap.Convertor(); var pointArr = []; pointArr.push(ggPoint); convertor.translate(pointArr, 3, 5, translateCallback) convertor.translate(pointArr, 1, 5, translateCallback2) }, 1000); </script> |