为什么转换以后的百度经纬度偏差还很大?

williamxia8 2015-09-15 10:48:39
我是用html5来定位的,定位之后采用百度的转换接口对经纬度进行转换,可是转换之后还是有很大的偏差,而且在同一个房间里面,位置还变来变去的,这是为什么,是不是还需要一个纠偏算法呢?
...全文
1093 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
williamxia8 2015-09-21
  • 打赏
  • 举报
回复
引用 5 楼 ligyu110 的回复:
//调用 double xx = 116.268511, yy = 39.907581; double[] arr = TransForm.getTransForm(xx, yy, true); System.out.println(arr[0]+","+arr[1]+",火星坐标:"); arr = TransForm.getTransForm(xx, yy, false); System.out.println(arr[0]+","+arr[1]+",百度坐标:");
这个算法有问题的,转换之后误差更大了
williamxia8 2015-09-21
  • 打赏
  • 举报
回复
引用 7 楼 sp1234 的回复:
不过有时候还是要看有没有具体细节造成偏差。例如你在房间里,那么你的经纬度是怎么测出来的?这个要知道你才知道结果会怎样。比如说你看到的经纬度可能是某个电信机房的,而你的wifi所连的小区宽带接入商的设备可能当时本身就是“飘来飘去”地在闹鬼呢,那么你如果改为使用移动网络连网,也许就好一些了。
那么为什么现在有些跑步用的软件,可以把路线精确画出来呢?
老李家的小二 2015-09-21
  • 打赏
  • 举报
回复
如果楼主要求高精度的定位,估计没什么好办法了
  • 打赏
  • 举报
回复
不过有时候还是要看有没有具体细节造成偏差。例如你在房间里,那么你的经纬度是怎么测出来的?这个要知道你才知道结果会怎样。比如说你看到的经纬度可能是某个电信机房的,而你的wifi所连的小区宽带接入商的设备可能当时本身就是“飘来飘去”地在闹鬼呢,那么你如果改为使用移动网络连网,也许就好一些了。
老李家的小二 2015-09-17
  • 打赏
  • 举报
回复
//调用 double xx = 116.268511, yy = 39.907581; double[] arr = TransForm.getTransForm(xx, yy, true); System.out.println(arr[0]+","+arr[1]+",火星坐标:"); arr = TransForm.getTransForm(xx, yy, false); System.out.println(arr[0]+","+arr[1]+",百度坐标:");
老李家的小二 2015-09-17
  • 打赏
  • 举报
回复
/***************WGS-84(GPS) /***************GCJ-02(Google地图) /***************BD-09(百度地图) */ private static double a = 6378245.0; //卫星椭球坐标投影到平面地图坐标系的投影因子 private static double ee = 0.00669342162296594323; //椭球的偏心率 static double x_pi = Math.PI * 3000.0 / 180.0; /** * 谷歌 --> 百度 * GCJ-02 --> BD-09 * @param gg_lon * @param gg_lat * @return */ public static double[] bd_encrypt(double gg_lon, double gg_lat) { double x = gg_lon, y = gg_lat; double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi); double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi); double[] arr = new double[2]; arr[0] = (double)(Math.round((z * Math.cos(theta) + 0.0065) * 1000000) / 1000000.0); arr[1] = (double)(Math.round((z * Math.sin(theta) + 0.006) * 1000000) / 1000000.0); return arr; } /** * 百度 --> 谷歌 * BD-09 --> GCJ-02 * @param bd_lon * @param bd_lat * @return */ public static double[] bd_decrypt(double bd_lon, double bd_lat) { double x = bd_lon - 0.0065, y = bd_lat - 0.006; double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi); double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi); double[] arr = new double[2]; arr[0] = (double)(Math.round((z * Math.cos(theta)) * 1000000) / 1000000.0); arr[1] = (double)(Math.round((z * Math.sin(theta)) * 1000000) / 1000000.0); return arr; } /** * GPS --> 谷歌/百度 * WGS-84 --> GCJ-02 * WGS-84 --> BD-09 * @param wgLon X * @param wgLat Y * @param toGoogle:true谷歌/false百度 * @return */ public static double[] getTransForm(double wgLon, double wgLat, boolean toGoogle) { if (outOfChina(wgLat, wgLon)) return null; double[] arr = new double[2]; double dLat = transformLat(wgLon - 105.0, wgLat - 35.0); double dLon = transformLon(wgLon - 105.0, wgLat - 35.0); double radLat = wgLat / 180.0 * Math.PI; double magic = Math.sin(radLat); magic = 1 - ee * magic * magic; double sqrtMagic = Math.sqrt(magic); dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * Math.PI); dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * Math.PI); //System.out.println((wgLon + dLon) + "," + (wgLat + dLat)); double x = wgLon + dLon; double y = wgLat + dLat; if(toGoogle) { arr[0] = (double)(Math.round(x * 1000000) / 1000000.0);//X arr[1] = (double)(Math.round(y * 1000000) / 1000000.0);//Y } else { arr = bd_encrypt(x, y); //double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi); //double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi); //arr[0] = (double)(Math.round((z * Math.cos(theta) + 0.0065) * 1000000) / 1000000.0);//X //arr[1] = (double)(Math.round((z * Math.sin(theta) + 0.006) * 1000000) / 1000000.0);//Y } return arr; } /** * 坐标范围是否在中国范围内 * @param lat * @param lon * @return */ private static boolean outOfChina(double lat, double lon) { if (lon < 72.004 || lon > 137.8347) return true; if (lat < 0.8293 || lat > 55.8271) return true; return false; } /** * Y坐标值转换 * @param x * @param y * @return */ private static double transformLat(double x, double y) { double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * Math.sqrt(Math.abs(x)); ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0; ret += (20.0 * Math.sin(y * Math.PI) + 40.0 * Math.sin(y / 3.0 * Math.PI)) * 2.0 / 3.0; ret += (160.0 * Math.sin(y / 12.0 * Math.PI) + 320 * Math.sin(y * Math.PI / 30.0)) * 2.0 / 3.0; return ret; } /** * X坐标值转换 * @param x * @param y * @return */ private static double transformLon(double x, double y) { double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x)); ret += (20.0 * Math.sin(6.0 * x * Math.PI) + 20.0 * Math.sin(2.0 * x * Math.PI)) * 2.0 / 3.0; ret += (20.0 * Math.sin(x * Math.PI) + 40.0 * Math.sin(x / 3.0 * Math.PI)) * 2.0 / 3.0; ret += (150.0 * Math.sin(x / 12.0 * Math.PI) + 300.0 * Math.sin(x / 30.0 * Math.PI)) * 2.0 / 3.0; return ret; }
williamxia8 2015-09-17
  • 打赏
  • 举报
回复
引用 2 楼 ligyu110 的回复:
是这样的,每次转换后的坐标都不一样
是不是在用百度转换之前,要先对获取到的经纬度进行纠偏呢?
老李家的小二 2015-09-15
  • 打赏
  • 举报
回复
是这样的,每次转换后的坐标都不一样
williamxia8 2015-09-15
  • 打赏
  • 举报
回复
用的是下面这个转换接口 //百度坐标转换API string url = "http://api.map.baidu.com/ag/coord/convert?from=0&to=4&x=" + Longitude + "&y=" + Latitude + "";

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧