google 高德地图纠偏

  1. /** 
  2.  * gps纠偏算法,适用于google,高德体系的地图 
  3.  * @author Administrator 
  4.  */  
  5. public class GpsCorrect {  
  6.     final static double pi = 3.14159265358979324;  
  7.     final static double a = 6378245.0;  
  8.     final static double ee = 0.00669342162296594323;  
  9.   
  10.     public static void transform(double wgLat, double wgLon, double[] latlng) {  
  11.         if (outOfChina(wgLat, wgLon)) {  
  12.             latlng[0] = wgLat;  
  13.             latlng[1] = wgLon;  
  14.             return;  
  15.         }  
  16.         double dLat = transformLat(wgLon - 105.0, wgLat - 35.0);  
  17.         double dLon = transformLon(wgLon - 105.0, wgLat - 35.0);  
  18.         double radLat = wgLat / 180.0 * pi;  
  19.         double magic = Math.sin(radLat);  
  20.         magic = 1 - ee * magic * magic;  
  21.         double sqrtMagic = Math.sqrt(magic);  
  22.         dLat = (dLat * 180.0) / ((a * (1 - ee)) / (magic * sqrtMagic) * pi);  
  23.         dLon = (dLon * 180.0) / (a / sqrtMagic * Math.cos(radLat) * pi);  
  24.         latlng[0] = wgLat + dLat;  
  25.         latlng[1] = wgLon + dLon;  
  26.     }  
  27.   
  28.     private static boolean outOfChina(double lat, double lon) {  
  29.         if (lon < 72.004 || lon > 137.8347)  
  30.             return true;  
  31.         if (lat < 0.8293 || lat > 55.8271)  
  32.             return true;  
  33.         return false;  
  34.     }  
  35.   
  36.     private static double transformLat(double x, double y) {  
  37.         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));  
  38.         ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;  
  39.         ret += (20.0 * Math.sin(y * pi) + 40.0 * Math.sin(y / 3.0 * pi)) * 2.0 / 3.0;  
  40.         ret += (160.0 * Math.sin(y / 12.0 * pi) + 320 * Math.sin(y * pi / 30.0)) * 2.0 / 3.0;  
  41.         return ret;  
  42.     }  
  43.   
  44.     private static double transformLon(double x, double y) {  
  45.         double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));  
  46.         ret += (20.0 * Math.sin(6.0 * x * pi) + 20.0 * Math.sin(2.0 * x * pi)) * 2.0 / 3.0;  
  47.         ret += (20.0 * Math.sin(x * pi) + 40.0 * Math.sin(x / 3.0 * pi)) * 2.0 / 3.0;  
  48.         ret += (150.0 * Math.sin(x / 12.0 * pi) + 300.0 * Math.sin(x / 30.0 * pi)) * 2.0 / 3.0;  
  49.         return ret;  
  50.     }  
  51. }  
Right! is "Fuck GIS",but don't think too much; It means reach a high during playing GIS. Come on!
原文地址:https://www.cnblogs.com/jsbrml/p/6093928.html