traccar-server源代码编译环境搭建

好记性不如乱笔头,记下来总是好的。。。
回复
BG6RSH
帖子: 89
注册时间: 周日 6月 23, 2019 12:00 pm

traccar-server源代码编译环境搭建

帖子 BG6RSH »

一、安装编译软件及支持软件:
1、安装IntelliJ IDEA Community版编译软件(免费的哦)https://www.jetbrains.com/idea/download ... on=windows
2、安装JDK(TM)8 64位、Java(TM) 8 64位,利用360软件管家还是很方便的
3、安装Git 64位,这个不是必须的,下载、同步源代码用

二、下载源代码:
1、在 https://github.com/traccar/traccar (后端)和 https://github.com/traccar/traccar-web (前端)下载最新的源代码。
2、或者用git下载 :git clone --recursive https://github.com/traccar/traccar.git

三、修改gradle下载依赖jar包为国内源,提高下载速度:
打开源代码根目录下的 build.gradle 文件,将“repositories”节内容修改为:
  1. repositories {
  2.     maven{ url'http://maven.aliyun.com/nexus/content/groups/public/'}   // 新增阿里源
  3.     mavenCentral()
  4. }


四、导入源代码:
参考“ https://www.traccar.org/build-in-intellij-idea/ ”内容,是不是成功了。
BG6RSH
帖子: 89
注册时间: 周日 6月 23, 2019 12:00 pm

Re: traccar-server源代码编译环境搭建

帖子 BG6RSH »

五、前端源代码修改
1、 traccar-web/web/l10n/zh.json 文件中添加高德地图选项: "mapAmap": "高德地图",如下图:
web-1.PNG
web-1.PNG (31.44 KiB) 查看 1940 次
2、traccar-web/web/app/view/map/BaseMap.js文件41行添加高德地图调用:
  1.             case 'amap':
  2.                 layer = new ol.layer.Tile({
  3.                     source: new ol.source.XYZ({
  4.                        url: 'https://webrd01.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={x}&y={y}&z={z}',
  5.                        attributions: '&copy; <a href="https://ditu.amap.com/">高德</a>'
  6.                     })
  7.                 });
  8.                 break;
见下图:
web-2.PNG
web-2.PNG (45.4 KiB) 查看 1940 次
3、traccar-web/web/app/store/MapTypes.js 添加下列代码:
  1.         key: 'amap',
  2.         name: Strings.mapAmap
  3.     }, {
如下图:
web-3.PNG
web-3.PNG (32.08 KiB) 查看 1940 次
BG6RSH
帖子: 89
注册时间: 周日 6月 23, 2019 12:00 pm

Re: traccar-server源代码编译环境搭建

帖子 BG6RSH »

六、源代码压缩打包:
1、Extjs6.2.0支持库:
ext-6.2.0-gpl.zip
(160.86 MiB) 下载 93 次
,下载后解压到随便那个地方;
2、根据操作系统选择32、64位SenchaCmd下载,按默认选择安装。
SenchaCmd6.2.2 32位
SenchaCmd6.2.2 64位
3、修改“\traccar\traccar-web\tools\minify.bat”
  1. @echo off
  2. cd C:\[traccar path]\traccar-web\web
  3. set SDK=C:\[sencha path]\ext-6.2.0
根据Extjs6.2.0支持库解压目录和TRACCAR的WEB源代码目录修改文件内容。
4、运行“minify.bat”批处理程序,会在“\traccar-web\web”目录生成一个“app.min.js”文件,这个也是需要上传到服务器的文件。
BG6RSH
帖子: 89
注册时间: 周日 6月 23, 2019 12:00 pm

Re: traccar-server源代码编译环境搭建

帖子 BG6RSH »

七、后台服务器修改:
1、逆地址编码调用MainModule.java
  1. Index: src/main/java/org/traccar/MainModule.java
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- src/main/java/org/traccar/MainModule.java   (revision cdf892cd39c528929284728562beef3220e91cf3)
  7. +++ src/main/java/org/traccar/MainModule.java   (date 1606206019169)
  8. @@ -29,22 +29,7 @@
  9.  import org.traccar.database.IdentityManager;
  10.  import org.traccar.database.MaintenancesManager;
  11.  import org.traccar.database.StatisticsManager;
  12. -import org.traccar.geocoder.AddressFormat;
  13. -import org.traccar.geocoder.BanGeocoder;
  14. -import org.traccar.geocoder.BingMapsGeocoder;
  15. -import org.traccar.geocoder.FactualGeocoder;
  16. -import org.traccar.geocoder.GeocodeFarmGeocoder;
  17. -import org.traccar.geocoder.GeocodeXyzGeocoder;
  18. -import org.traccar.geocoder.Geocoder;
  19. -import org.traccar.geocoder.GisgraphyGeocoder;
  20. -import org.traccar.geocoder.GoogleGeocoder;
  21. -import org.traccar.geocoder.HereGeocoder;
  22. -import org.traccar.geocoder.MapQuestGeocoder;
  23. -import org.traccar.geocoder.MapmyIndiaGeocoder;
  24. -import org.traccar.geocoder.NominatimGeocoder;
  25. -import org.traccar.geocoder.OpenCageGeocoder;
  26. -import org.traccar.geocoder.PositionStackGeocoder;
  27. -import org.traccar.geocoder.TomTomGeocoder;
  28. +import org.traccar.geocoder.*;
  29.  import org.traccar.geolocation.GeolocationProvider;
  30.  import org.traccar.geolocation.GoogleGeolocationProvider;
  31.  import org.traccar.geolocation.MozillaGeolocationProvider;
  32. @@ -184,6 +169,9 @@
  33.                      return new TomTomGeocoder(url, key, cacheSize, addressFormat);
  34.                  case "positionstack":
  35.                      return new PositionStackGeocoder(key, cacheSize, addressFormat);
  36. +                /*** 高德地图反向地理编码***/
  37. +                case "amap":
  38. +                    return new AmapGeocoder(url, key, cacheSize, addressFormat);
  39.                  default:
  40.                      return new GoogleGeocoder(key, language, cacheSize, addressFormat);
  41.              }
2、JsonGeocoder.java
  1. Index: src/main/java/org/traccar/geocoder/JsonGeocoder.java
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- src/main/java/org/traccar/geocoder/JsonGeocoder.java    (revision cdf892cd39c528929284728562beef3220e91cf3)
  7. +++ src/main/java/org/traccar/geocoder/JsonGeocoder.java    (date 1606208737428)
  8. @@ -28,6 +28,8 @@
  9.  import java.util.LinkedHashMap;
  10.  import java.util.Map;
  11.  
  12. +import org.traccar.config.Keys; // 高德适配
  13. +
  14.  public abstract class JsonGeocoder implements Geocoder {
  15.  
  16.      private static final Logger LOGGER = LoggerFactory.getLogger(JsonGeocoder.class);
  17. @@ -95,7 +97,14 @@
  18.              }
  19.          }
  20.  
  21. -        Invocation.Builder request = Context.getClient().target(String.format(url, latitude, longitude)).request();
  22. +        //Invocation.Builder request = Context.getClient().target(String.format(url, latitude, longitude)).request();
  23. +        // 高德适配
  24. +        String type = Context.getConfig().getString(Keys.GEOCODER_TYPE, "google");
  25. +        Invocation.Builder request;
  26. +        if(type.equals("amap"))  // 高德地图适配
  27. +            request = Context.getClient().target(String.format(url, longitude, latitude)).request();
  28. +        else
  29. +            request = Context.getClient().target(String.format(url, latitude, longitude)).request();
  30.  
  31.          if (callback != null) {
  32.              request.async().get(new InvocationCallback<JsonObject>() {
上次由 BG6RSH 在 周五 11月 27, 2020 10:53 pm,总共编辑 1 次。
BG6RSH
帖子: 89
注册时间: 周日 6月 23, 2019 12:00 pm

Re: traccar-server源代码编译环境搭建

帖子 BG6RSH »

3、OsmAndProtocolDecoder.java
  1. Index: src/main/java/org/traccar/protocol/OsmAndProtocolDecoder.java
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- src/main/java/org/traccar/protocol/OsmAndProtocolDecoder.java   (revision cdf892cd39c528929284728562beef3220e91cf3)
  7. +++ src/main/java/org/traccar/protocol/OsmAndProtocolDecoder.java   (date 1606201926801)
  8. @@ -60,6 +60,11 @@
  9.          Position position = new Position(getProtocolName());
  10.          position.setValid(true);
  11.  
  12. +        /* 坐标转换 WGS84 -> GCJ02  BD09*/
  13. +        Double tlat = Double.parseDouble(params.get("lat").get(0));
  14. +        Double tlon = Double.parseDouble(params.get("lon").get(0));
  15. +        double pos_gcj02[] = GpsCoordinateUtils.calWGS84toGCJ02(tlat, tlon);
  16. +        //double pos_bd09[]  = GpsCoordinateUtils.calWGS84toBD09(tlat, tlon);
  17.          Network network = new Network();
  18.  
  19.          for (Map.Entry<String, List<String>> entry : params.entrySet()) {
  20. @@ -94,15 +99,21 @@
  21.                          }
  22.                          break;
  23.                      case "lat":
  24. -                        position.setLatitude(Double.parseDouble(value));
  25. +                        //position.setLatitude(Double.parseDouble(value));  // WGS84
  26. +                        position.setLatitude(pos_gcj02[0]);  // GCJ02
  27. +                        //position.setLatitude_bd09(pos_bd09[0]);  // BD09
  28.                          break;
  29.                      case "lon":
  30. -                        position.setLongitude(Double.parseDouble(value));
  31. +                        //position.setLongitude(Double.parseDouble(value));  // WGS84
  32. +                        position.setLongitude(pos_gcj02[1]);  // GCJ02
  33. +                        //position.setLongitude_bd09(pos_bd09[1]);  // BD09
  34.                          break;
  35.                      case "location":
  36. -                        String[] location = value.split(",");
  37. -                        position.setLatitude(Double.parseDouble(location[0]));
  38. -                        position.setLongitude(Double.parseDouble(location[1]));
  39. +                        //String[] location = value.split(",");
  40. +                        //position.setLatitude(Double.parseDouble(location[0]));
  41. +                        //position.setLongitude(Double.parseDouble(location[1]));
  42. +                        position.setLatitude(pos_gcj02[0]);  // GCJ02
  43. +                        position.setLongitude(pos_gcj02[1]);  // GCJ02
  44.                          break;
  45.                      case "cell":
  46.                          String[] cell = value.split(",");
上次由 BG6RSH 在 周五 11月 27, 2020 10:53 pm,总共编辑 1 次。
BG6RSH
帖子: 89
注册时间: 周日 6月 23, 2019 12:00 pm

Re: traccar-server源代码编译环境搭建

帖子 BG6RSH »

4、GpsCoordinateUtils.java
  1. Index: src/main/java/org/traccar/protocol/GpsCoordinateUtils.java
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. package org.traccar.protocol;
  7.  
  8. import java.util.ArrayList;
  9. import java.util.List;
  10. import java.util.Arrays;
  11.  
  12. /**
  13.  * 地图坐标转换
  14.  * http://bbs.atoo.top:8081
  15.  */
  16. public class GpsCoordinateUtils {
  17.  
  18.     private static final double PI = 3.1415926535897932384626433832795;
  19.     //    private static final double PI = 3.14159265358979324;
  20.     private static final double A = 6378245.0;
  21.     private static final double EE = 0.00669342162296594323;
  22.  
  23.     /**
  24.      * 地球坐标系 WGS-84 to 火星坐标系 GCJ-02
  25.      *
  26.      * @param latitude  纬度
  27.      * @param longitude 经度
  28.      * @return [纬度, 经度]
  29.      */
  30.     public static double[] calWGS84toGCJ02(double latitude, double longitude) {
  31.         Point dev = calDev(latitude, longitude);
  32.         double retLat = latitude + dev.getLatitude();
  33.         double retLon = longitude + dev.getLongitude();
  34.         return new double[]{retLat, retLon};
  35.     }
  36.  
  37.     /**
  38.      * 地球坐标系 WGS-84 to 百度坐标系 BD-09
  39.      *
  40.      * @param latitude  纬度
  41.      * @param longitude 经度
  42.      * @return [纬度, 经度]
  43.      */
  44.     public static double[] calWGS84toBD09(double latitude, double longitude) {
  45.         Point dev = calDev(latitude, longitude);
  46.         double retLat = latitude + dev.getLatitude();
  47.         double retLon = longitude + dev.getLongitude();
  48.         return calGCJ02toBD09(retLat, retLon);
  49.     }
  50.  
  51.     /**
  52.      * 火星坐标系 GCJ-02 to 地球坐标系 WGS-84
  53.      *
  54.      * @param latitude  纬度
  55.      * @param longitude 经度
  56.      * @return [纬度, 经度]
  57.      */
  58.     public static double[] calGCJ02toWGS84(double latitude, double longitude) {
  59.         Point dev = calDev(latitude, longitude);
  60.         double retLat = latitude - dev.getLatitude();
  61.         double retLon = longitude - dev.getLongitude();
  62.         dev = calDev(retLat, retLon);
  63.         retLat = latitude - dev.getLatitude();
  64.         retLon = longitude - dev.getLongitude();
  65.         return new double[]{retLat, retLon};
  66.     }
  67.  
  68.     /**
  69.      * 百度坐标系 BD-09 to 地球坐标系 WGS-84
  70.      *
  71.      * @param latitude  纬度
  72.      * @param longitude 经度
  73.      * @return [纬度, 经度]
  74.      */
  75.     public static double[] calBD09toWGS84(double latitude, double longitude) {
  76.         double[] gcj = calBD09toGCJ02(latitude, longitude);
  77.         return calGCJ02toWGS84(gcj[0], gcj[1]);
  78.     }
  79.  
  80.     private static Point calDev(double latitude, double longitude) {
  81.         if (isOutOfChina(latitude, longitude, false)) {
  82.             return new Point(latitude, latitude);
  83.         }
  84.         double dLat = calLat(longitude - 105.0, latitude - 35.0);
  85.         double dLon = calLon(longitude - 105.0, latitude - 35.0);
  86.         double radLat = latitude / 180.0 * PI;
  87.         double magic = Math.sin(radLat);
  88.         magic = 1 - EE * magic * magic;
  89.         double sqrtMagic = Math.sqrt(magic);
  90.         dLat = (dLat * 180.0) / ((A * (1 - EE)) / (magic * sqrtMagic) * PI);
  91.         dLon = (dLon * 180.0) / (A / sqrtMagic * Math.cos(radLat) * PI);
  92.         return new Point(dLat, dLon);
  93.     }
  94.  
  95.     private static double calLat(double x, double y) {
  96.         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));
  97.         ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
  98.         ret += (20.0 * Math.sin(y * PI) + 40.0 * Math.sin(y / 3.0 * PI)) * 2.0 / 3.0;
  99.         ret += (160.0 * Math.sin(y / 12.0 * PI) + 320 * Math.sin(y * PI / 30.0)) * 2.0 / 3.0;
  100.         return ret;
  101.     }
  102.  
  103.     private static double calLon(double x, double y) {
  104.         double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * Math.sqrt(Math.abs(x));
  105.         ret += (20.0 * Math.sin(6.0 * x * PI) + 20.0 * Math.sin(2.0 * x * PI)) * 2.0 / 3.0;
  106.         ret += (20.0 * Math.sin(x * PI) + 40.0 * Math.sin(x / 3.0 * PI)) * 2.0 / 3.0;
  107.         ret += (150.0 * Math.sin(x / 12.0 * PI) + 300.0 * Math.sin(x / 30.0 * PI)) * 2.0 / 3.0;
  108.         return ret;
  109.     }
  110.  
  111.     /**
  112.      * 火星坐标系 GCJ-02 to 百度坐标系 BD-09
  113.      *
  114.      * @param latitude  纬度
  115.      * @param longitude 经度
  116.      * @return [纬度, 经度]
  117.      */
  118.     public static double[] calGCJ02toBD09(double latitude, double longitude) {
  119.         double x = longitude, y = latitude;
  120.         double z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * PI);
  121.         double theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * PI);
  122.         double retLat = z * Math.sin(theta) + 0.006;
  123.         double retLon = z * Math.cos(theta) + 0.0065;
  124.         return new double[]{retLat, retLon};
  125.     }
  126.  
  127.     /**
  128.      * 百度坐标系 BD-09 to 火星坐标系 GCJ-02
  129.      *
  130.      * @param latitude  纬度
  131.      * @param longitude 经度
  132.      * @return [纬度, 经度]
  133.      */
  134.     public static double[] calBD09toGCJ02(double latitude, double longitude) {
  135.         double x = longitude - 0.0065, y = latitude - 0.006;
  136.         double z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * PI);
  137.         double theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * PI);
  138.         double retLat = z * Math.sin(theta);
  139.         double retLon = z * Math.cos(theta);
  140.         return new double[]{retLat, retLon};
  141.     }
  142.  
  143.     /**
  144.      * 判断坐标是否在国内
  145.      *
  146.      * @param latitude
  147.      * @param longitude
  148.      * @param precision 是否精确判断范围
  149.      * @return true 在国外,false 在国内
  150.      */
  151.     public static boolean isOutOfChina(double latitude, double longitude, boolean precision) {
  152.         if (precision) {
  153.             return CHINA_POLYGON.stream().noneMatch(point -> pointInPolygon(point, latitude, longitude));
  154.         } else {
  155.             if (longitude < 72.004 || longitude > 137.8347) {
  156.                 return true;
  157.             }
  158.             if (latitude < 0.8293 || latitude > 55.8271) {
  159.                 return true;
  160.             }
  161.             return false;
  162.         }
  163.     }
  164.  
  165.     /**
  166.      * 检查坐标点是否在多边形区域内
  167.      *
  168.      * @param polygon   多边形
  169.      * @param latitude  纬度
  170.      * @param longitude 经度
  171.      * @return true 在多边形区域内,false 在多边形区域外
  172.      */
  173.     private static boolean pointInPolygon(Point[] polygon, double latitude, double longitude) {
  174.         int i, j = polygon.length - 1;
  175.         boolean oddNodes = false;
  176.         for (i = 0; i < polygon.length; i++) {
  177.             if ((polygon[i].getLatitude() < latitude && polygon[j].getLatitude() >= latitude
  178.                     || polygon[j].getLatitude() < latitude && polygon[i].getLatitude() >= latitude)
  179.                     && (polygon[i].getLongitude() <= longitude || polygon[j].getLongitude() <= longitude)) {
  180.                 if (polygon[i].getLongitude()
  181.                         + (latitude - polygon[i].getLatitude()) / (polygon[j].getLatitude() - polygon[i].getLatitude())
  182.                         * (polygon[j].getLongitude() - polygon[i].getLongitude())
  183.                         < longitude) {
  184.                     oddNodes = !oddNodes;
  185.                 }
  186.             }
  187.             j = i;
  188.         }
  189.         return oddNodes;
  190.     }
  191.  
  192.     static class Point {
  193.         private double longitude;
  194.         private double latitude;
  195.  
  196.         Point(double latitude, double longitude) {
  197.             this.longitude = longitude;
  198.             this.latitude = latitude;
  199.         }
  200.  
  201.         public double getLongitude() {
  202.             return longitude;
  203.         }
  204.  
  205.         public void setLongitude(double longitude) {
  206.             this.longitude = longitude;
  207.         }
  208.  
  209.         public double getLatitude() {
  210.             return latitude;
  211.         }
  212.  
  213.         public void setLatitude(double latitude) {
  214.             this.latitude = latitude;
  215.         }
  216.  
  217.         @Override
  218.         public String toString() {
  219.             return longitude + "," + latitude;
  220.         }
  221.     }
  222.  
  223.     //region 中国行政边界的WGS84坐标数据
  224.     //Mainland
  225.     private static final Point[] MAINLAND = new Point[]{
  226.             new Point(27.32083, 88.91693),
  227.             new Point(27.54243, 88.76464),
  228.             new Point(28.00805, 88.83575),
  229.             new Point(28.1168, 88.62435),
  230.             new Point(27.86605, 88.14279),
  231.             new Point(27.82305, 87.19275),
  232.             new Point(28.11166, 86.69527),
  233.             new Point(27.90888, 86.45137),
  234.             new Point(28.15805, 86.19769),
  235.             new Point(27.88625, 86.0054),
  236.             new Point(28.27916, 85.72137),
  237.             new Point(28.30666, 85.11095),
  238.             new Point(28.59104, 85.19518),
  239.             new Point(28.54444, 84.84665),
  240.             new Point(28.73402, 84.48623),
  241.             new Point(29.26097, 84.11651),
  242.             new Point(29.18902, 83.5479),
  243.             new Point(29.63166, 83.19109),
  244.             new Point(30.06923, 82.17525),
  245.             new Point(30.33444, 82.11123),
  246.             new Point(30.385, 81.42623),
  247.             new Point(30.01194, 81.23221),
  248.             new Point(30.20435, 81.02536),
  249.             new Point(30.57552, 80.207),
  250.             new Point(30.73374, 80.25423),
  251.             new Point(30.96583, 79.86304),
  252.             new Point(30.95708, 79.55429),
  253.             new Point(31.43729, 79.08082),
  254.             new Point(31.30895, 78.76825),
  255.             new Point(31.96847, 78.77075),
  256.             new Point(32.24304, 78.47594),
  257.             new Point(32.5561, 78.40595),
  258.             new Point(32.63902, 78.74623),
  259.             new Point(32.35083, 78.9711),
  260.             new Point(32.75666, 79.52874),
  261.             new Point(33.09944, 79.37511),
  262.             new Point(33.42863, 78.93623),
  263.             new Point(33.52041, 78.81387),
  264.             new Point(34.06833, 78.73581),
  265.             new Point(34.35001, 78.98535),
  266.             new Point(34.6118, 78.33707),
  267.             new Point(35.28069, 78.02305),
  268.             new Point(35.49902, 78.0718),
  269.             new Point(35.50133, 77.82393),
  270.             new Point(35.6125, 76.89526),
  271.             new Point(35.90665, 76.55304),
  272.             new Point(35.81458, 76.18061),
  273.             new Point(36.07082, 75.92887),
  274.             new Point(36.23751, 76.04166),
  275.             new Point(36.66343, 75.85984),
  276.             new Point(36.73169, 75.45179),
  277.             new Point(36.91156, 75.39902),
  278.             new Point(36.99719, 75.14787),
  279.             new Point(37.02782, 74.56543),
  280.             new Point(37.17, 74.39089),
  281.             new Point(37.23733, 74.91574),
  282.             new Point(37.40659, 75.18748),
  283.             new Point(37.65243, 74.9036),
  284.             new Point(38.47256, 74.85442),
  285.             new Point(38.67438, 74.35471),
  286.             new Point(38.61271, 73.81401),
  287.             new Point(38.88653, 73.70818),
  288.             new Point(38.97256, 73.85235),
  289.             new Point(39.23569, 73.62005),
  290.             new Point(39.45483, 73.65569),
  291.             new Point(39.59965, 73.95471),
  292.             new Point(39.76896, 73.8429),
  293.             new Point(40.04202, 73.99096),
  294.             new Point(40.32792, 74.88089),
  295.             new Point(40.51723, 74.8588),
  296.             new Point(40.45042, 75.23394),
  297.             new Point(40.64452, 75.58284),
  298.             new Point(40.298, 75.70374),
  299.             new Point(40.35324, 76.3344),
  300.             new Point(41.01258, 76.87067),
  301.             new Point(41.04079, 78.08083),
  302.             new Point(41.39286, 78.39554),
  303.             new Point(42.03954, 80.24513),
  304.             new Point(42.19622, 80.23402),
  305.             new Point(42.63245, 80.15804),
  306.             new Point(42.81565, 80.25796),
  307.             new Point(42.88545, 80.57226),
  308.             new Point(43.02906, 80.38405),
  309.             new Point(43.1683, 80.81526),
  310.             new Point(44.11378, 80.36887),
  311.             new Point(44.6358, 80.38499),
  312.             new Point(44.73408, 80.51589),
  313.             new Point(44.90282, 79.87106),
  314.             new Point(45.3497, 81.67928),
  315.             new Point(45.15748, 81.94803),
  316.             new Point(45.13303, 82.56638),
  317.             new Point(45.43581, 82.64624),
  318.             new Point(45.5831, 82.32179),
  319.             new Point(47.20061, 83.03443),
  320.             new Point(46.97332, 83.93026),
  321.             new Point(46.99361, 84.67804),
  322.             new Point(46.8277, 84.80318),
  323.             new Point(47.0591, 85.52257),
  324.             new Point(47.26221, 85.70139),
  325.             new Point(47.93721, 85.53707),
  326.             new Point(48.39333, 85.76596),
  327.             new Point(48.54277, 86.59791),
  328.             new Point(49.1102, 86.87602),
  329.             new Point(49.09262, 87.34821),
  330.             new Point(49.17295, 87.8407),
  331.             new Point(48.98304, 87.89291),
  332.             new Point(48.88103, 87.7611),
  333.             new Point(48.73499, 88.05942),
  334.             new Point(48.56541, 87.99194),
  335.             new Point(48.40582, 88.51679),
  336.             new Point(48.21193, 88.61179),
  337.             new Point(47.99374, 89.08514),
  338.             new Point(47.88791, 90.07096),
  339.             new Point(46.95221, 90.9136),
  340.             new Point(46.57735, 91.07027),
  341.             new Point(46.29694, 90.92151),
  342.             new Point(46.01735, 91.02651),
  343.             new Point(45.57972, 90.68193),
  344.             new Point(45.25305, 90.89694),
  345.             new Point(45.07729, 91.56088),
  346.             new Point(44.95721, 93.5547),
  347.             new Point(44.35499, 94.71735),
  348.             new Point(44.29416, 95.41061),
  349.             new Point(44.01937, 95.34109),
  350.             new Point(43.99311, 95.53339),
  351.             new Point(43.28388, 95.87901),
  352.             new Point(42.73499, 96.38206),
  353.             new Point(42.79583, 97.1654),
  354.             new Point(42.57194, 99.51012),
  355.             new Point(42.67707, 100.8425),
  356.             new Point(42.50972, 101.8147),
  357.             new Point(42.23333, 102.0772),
  358.             new Point(41.88721, 103.4164),
  359.             new Point(41.87721, 104.5267),
  360.             new Point(41.67068, 104.5237),
  361.             new Point(41.58666, 105.0065),
  362.             new Point(42.46624, 107.4758),
  363.             new Point(42.42999, 109.3107),
  364.             new Point(42.64576, 110.1064),
  365.             new Point(43.31694, 110.9897),
  366.             new Point(43.69221, 111.9583),
  367.             new Point(44.37527, 111.4214),
  368.             new Point(45.04944, 111.873),
  369.             new Point(45.08055, 112.4272),
  370.             new Point(44.8461, 112.853),
  371.             new Point(44.74527, 113.638),
  372.             new Point(45.38943, 114.5453),
  373.             new Point(45.4586, 115.7019),
  374.             new Point(45.72193, 116.2104),
  375.             new Point(46.29583, 116.5855),
  376.             new Point(46.41888, 117.3755),
  377.             new Point(46.57069, 117.425),
  378.             new Point(46.53645, 117.8455),
  379.             new Point(46.73638, 118.3147),
  380.             new Point(46.59895, 119.7068),
  381.             new Point(46.71513, 119.9315),
  382.             new Point(46.90221, 119.9225),
  383.             new Point(47.66499, 119.125),
  384.             new Point(47.99475, 118.5393),
  385.             new Point(48.01125, 117.8046),
  386.             new Point(47.65741, 117.3827),
  387.             new Point(47.88805, 116.8747),
  388.             new Point(47.87819, 116.2624),
  389.             new Point(47.69186, 115.9231),
  390.             new Point(47.91749, 115.5944),
  391.             new Point(48.14353, 115.5491),
  392.             new Point(48.25249, 115.8358),
  393.             new Point(48.52055, 115.8111),
  394.             new Point(49.83047, 116.7114),
  395.             new Point(49.52058, 117.8747),
  396.             new Point(49.92263, 118.5746),
  397.             new Point(50.09631, 119.321),
  398.             new Point(50.33028, 119.36),
  399.             new Point(50.39027, 119.1386),
  400.             new Point(51.62083, 120.0641),
  401.             new Point(52.115, 120.7767),
  402.             new Point(52.34423, 120.6259),
  403.             new Point(52.54267, 120.7122),
  404.             new Point(52.58805, 120.0819),
  405.             new Point(52.76819, 120.0314),
  406.             new Point(53.26374, 120.8307),
  407.             new Point(53.54361, 123.6147),
  408.             new Point(53.18832, 124.4933),
  409.             new Point(53.05027, 125.62),
  410.             new Point(52.8752, 125.6573),
  411.             new Point(52.75722, 126.0968),
  412.             new Point(52.5761, 125.9943),
  413.             new Point(52.12694, 126.555),
  414.             new Point(51.99437, 126.4412),
  415.             new Point(51.38138, 126.9139),
  416.             new Point(51.26555, 126.8176),
  417.             new Point(51.31923, 126.9689),
  418.             new Point(51.05825, 126.9331),
  419.             new Point(50.74138, 127.2919),
  420.             new Point(50.31472, 127.334),
  421.             new Point(50.20856, 127.5861),
  422.             new Point(49.80588, 127.515),
  423.             new Point(49.58665, 127.838),
  424.             new Point(49.58443, 128.7119),
  425.             new Point(49.34676, 129.1118),
  426.             new Point(49.4158, 129.4902),
  427.             new Point(48.86464, 130.2246),
  428.             new Point(48.86041, 130.674),
  429.             new Point(48.60576, 130.5236),
  430.             new Point(48.3268, 130.824),
  431.             new Point(48.10839, 130.6598),
  432.             new Point(47.68721, 130.9922),
  433.             new Point(47.71027, 132.5211),
  434.             new Point(48.09888, 133.0827),
  435.             new Point(48.06888, 133.4843),
  436.             new Point(48.39112, 134.4153),
  437.             new Point(48.26713, 134.7408),
  438.             new Point(47.99207, 134.5576),
  439.             new Point(47.70027, 134.7608),
  440.             new Point(47.32333, 134.1825),
  441.             new Point(46.64017, 133.9977),
  442.             new Point(46.47888, 133.8472),
  443.             new Point(46.25363, 133.9016),
  444.             new Point(45.82347, 133.4761),
  445.             new Point(45.62458, 133.4702),
  446.             new Point(45.45083, 133.1491),
  447.             new Point(45.05694, 133.0253),
  448.             new Point(45.34582, 131.8684),
  449.             new Point(44.97388, 131.4691),
  450.             new Point(44.83649, 130.953),
  451.             new Point(44.05193, 131.298),
  452.             new Point(43.53624, 131.1912),
  453.             new Point(43.38958, 131.3104),
  454.             new Point(42.91645, 131.1285),
  455.             new Point(42.74485, 130.4327),
  456.             new Point(42.42186, 130.6044),
  457.             new Point(42.71416, 130.2468),
  458.             new Point(42.88794, 130.2514),
  459.             new Point(43.00457, 129.9046),
  460.             new Point(42.43582, 129.6955),
  461.             new Point(42.44624, 129.3493),
  462.             new Point(42.02736, 128.9269),
  463.             new Point(42.00124, 128.0566),
  464.             new Point(41.58284, 128.3002),
  465.             new Point(41.38124, 128.1529),
  466.             new Point(41.47249, 127.2708),
  467.             new Point(41.79222, 126.9047),
  468.             new Point(41.61176, 126.5661),
  469.             new Point(40.89694, 126.0118),
  470.             new Point(40.47037, 124.8851),
  471.             new Point(40.09362, 124.3736),
  472.             new Point(39.82777, 124.128),
  473.             new Point(39.8143, 123.2422),
  474.             new Point(39.67388, 123.2167),
  475.             new Point(38.99638, 121.648),
  476.             new Point(38.8611, 121.6982),
  477.             new Point(38.71909, 121.1873),
  478.             new Point(38.91221, 121.0887),
  479.             new Point(39.09013, 121.6794),
  480.             new Point(39.2186, 121.5994),
  481.             new Point(39.35166, 121.7511),
  482.             new Point(39.52847, 121.2283),
  483.             new Point(39.62322, 121.533),
  484.             new Point(39.81138, 121.4683),
  485.             new Point(40.00305, 121.881),
  486.             new Point(40.50562, 122.2987),
  487.             new Point(40.73874, 122.0521),
  488.             new Point(40.92194, 121.1775),
  489.             new Point(40.1961, 120.4468),
  490.             new Point(39.87242, 119.5264),
  491.             new Point(39.15693, 118.9715),
  492.             new Point(39.04083, 118.3273),
  493.             new Point(39.19846, 117.889),
  494.             new Point(38.67555, 117.5364),
  495.             new Point(38.38666, 117.6722),
  496.             new Point(38.16721, 118.0281),
  497.             new Point(38.1529, 118.8378),
  498.             new Point(37.87832, 119.0355),
  499.             new Point(37.30054, 118.9566),
  500.             new Point(37.14361, 119.2328),
  501.             new Point(37.15138, 119.7672),
  502.             new Point(37.35228, 119.8529),
  503.             new Point(37.83499, 120.7371),
  504.             new Point(37.42458, 121.58),
  505.             new Point(37.55256, 122.1282),
  506.             new Point(37.41833, 122.1814),
  507.             new Point(37.39624, 122.5586),
  508.             new Point(37.20999, 122.5972),
  509.             new Point(37.02583, 122.4005),
  510.             new Point(37.01978, 122.5392),
  511.             new Point(36.89361, 122.5047),
  512.             new Point(36.84298, 122.1923),
  513.             new Point(37.00027, 121.9566),
  514.             new Point(36.75889, 121.5944),
  515.             new Point(36.61666, 120.7764),
  516.             new Point(36.52638, 120.96),
  517.             new Point(36.37582, 120.8753),
  518.             new Point(36.42277, 120.7062),
  519.             new Point(36.14075, 120.6956),
  520.             new Point(36.0419, 120.3436),
  521.             new Point(36.26345, 120.3078),
  522.             new Point(36.19998, 120.0889),
  523.             new Point(35.95943, 120.2378),
  524.             new Point(35.57893, 119.6475),
  525.             new Point(34.88499, 119.1761),
  526.             new Point(34.31145, 120.2487),
  527.             new Point(32.97499, 120.8858),
  528.             new Point(32.63889, 120.8375),
  529.             new Point(32.42958, 121.3348),
  530.             new Point(32.11333, 121.4412),
  531.             new Point(32.02166, 121.7066),
  532.             new Point(31.67833, 121.8275),
  533.             new Point(31.86639, 120.9444),
  534.             new Point(32.09361, 120.6019),
  535.             new Point(31.94555, 120.099),
  536.             new Point(32.30638, 119.8267),
  537.             new Point(32.26277, 119.6317),
  538.             new Point(31.90388, 120.1364),
  539.             new Point(31.98833, 120.7026),
  540.             new Point(31.81944, 120.7196),
  541.             new Point(31.30889, 121.6681),
  542.             new Point(30.97986, 121.8828),
  543.             new Point(30.85305, 121.8469),
  544.             new Point(30.56889, 120.9915),
  545.             new Point(30.33555, 120.8144),
  546.             new Point(30.39298, 120.4586),
  547.             new Point(30.19694, 120.15),
  548.             new Point(30.31027, 120.5082),
  549.             new Point(30.06465, 120.7916),
  550.             new Point(30.30458, 121.2808),
  551.             new Point(29.96305, 121.6778),
  552.             new Point(29.88211, 122.1196),
  553.             new Point(29.51167, 121.4483),
  554.             new Point(29.58916, 121.9744),
  555.             new Point(29.19527, 121.9336),
  556.             new Point(29.18388, 121.8119),
  557.             new Point(29.37236, 121.7969),
  558.             new Point(29.19729, 121.7444),
  559.             new Point(29.29111, 121.5611),
  560.             new Point(29.1634, 121.4135),
  561.             new Point(29.02194, 121.6914),
  562.             new Point(28.9359, 121.4908),
  563.             new Point(28.72798, 121.6113),
  564.             new Point(28.84215, 121.1464),
  565.             new Point(28.66993, 121.4844),
  566.             new Point(28.34722, 121.6417),
  567.             new Point(28.13889, 121.3419),
  568.             new Point(28.38277, 121.1651),
  569.             new Point(27.98222, 120.9353),
  570.             new Point(28.07944, 120.5908),
  571.             new Point(27.87229, 120.84),
  572.             new Point(27.59319, 120.5812),
  573.             new Point(27.45083, 120.6655),
  574.             new Point(27.20777, 120.5075),
  575.             new Point(27.28278, 120.1896),
  576.             new Point(27.14764, 120.4211),
  577.             new Point(26.89805, 120.0332),
  578.             new Point(26.64465, 120.128),
  579.             new Point(26.51778, 119.8603),
  580.             new Point(26.78823, 120.0733),
  581.             new Point(26.64888, 119.8668),
  582.             new Point(26.79611, 119.7879),
  583.             new Point(26.75625, 119.5503),
  584.             new Point(26.44222, 119.8204),
  585.             new Point(26.47388, 119.5775),
  586.             new Point(26.33861, 119.658),
  587.             new Point(26.36777, 119.9489),
  588.             new Point(25.99694, 119.4253),
  589.             new Point(26.14041, 119.0975),
  590.             new Point(25.93788, 119.354),
  591.             new Point(25.99069, 119.7058),
  592.             new Point(25.67996, 119.5807),
  593.             new Point(25.68222, 119.4522),
  594.             new Point(25.35333, 119.6454),
  595.             new Point(25.60649, 119.3149),
  596.             new Point(25.42097, 119.1053),
  597.             new Point(25.25319, 119.3526),
  598.             new Point(25.17208, 119.2726),
  599.             new Point(25.2426, 118.8749),
  600.             new Point(24.97194, 118.9866),
  601.             new Point(24.88291, 118.5729),
  602.             new Point(24.75673, 118.7631),
  603.             new Point(24.52861, 118.5953),
  604.             new Point(24.53638, 118.2397),
  605.             new Point(24.68194, 118.1688),
  606.             new Point(24.44024, 118.0199),
  607.             new Point(24.46019, 117.7947),
  608.             new Point(24.25875, 118.1237),
  609.             new Point(23.62437, 117.1957),
  610.             new Point(23.65919, 116.9179),
  611.             new Point(23.355, 116.7603),
  612.             new Point(23.42024, 116.5322),
  613.             new Point(23.23666, 116.7871),
  614.             new Point(23.21083, 116.5139),
  615.             new Point(22.93902, 116.4817),
  616.             new Point(22.73916, 115.7978),
  617.             new Point(22.88416, 115.6403),
  618.             new Point(22.65889, 115.5367),
  619.             new Point(22.80833, 115.1614),
  620.             new Point(22.70277, 114.8889),
  621.             new Point(22.53305, 114.8722),
  622.             new Point(22.64027, 114.718),
  623.             new Point(22.81402, 114.7782),
  624.             new Point(22.69972, 114.5208),
  625.             new Point(22.50423, 114.6136),
  626.             new Point(22.55004, 114.2223),
  627.             new Point(22.42993, 114.3885),
  628.             new Point(22.26056, 114.2961),
  629.             new Point(22.36736, 113.9056),
  630.             new Point(22.50874, 114.0337),
  631.             new Point(22.47444, 113.8608),
  632.             new Point(22.83458, 113.606),
  633.             new Point(23.05027, 113.5253),
  634.             new Point(23.11724, 113.8219),
  635.             new Point(23.05083, 113.4793),
  636.             new Point(22.87986, 113.3629),
  637.             new Point(22.54944, 113.5648),
  638.             new Point(22.18701, 113.5527),
  639.             new Point(22.56701, 113.1687),
  640.             new Point(22.17965, 113.3868),
  641.             new Point(22.04069, 113.2226),
  642.             new Point(22.20485, 113.0848),
  643.             new Point(21.8693, 112.94),
  644.             new Point(21.96472, 112.824),
  645.             new Point(21.70139, 112.2819),
  646.             new Point(21.91611, 111.8921),
  647.             new Point(21.75139, 111.9669),
  648.             new Point(21.77819, 111.6762),
  649.             new Point(21.61264, 111.7832),
  650.             new Point(21.5268, 111.644),
  651.             new Point(21.52528, 111.0285),
  652.             new Point(21.21138, 110.5328),
  653.             new Point(21.37322, 110.3944),
  654.             new Point(20.84381, 110.1594),
  655.             new Point(20.84083, 110.3755),
  656.             new Point(20.64, 110.3239),
  657.             new Point(20.48618, 110.5274),
  658.             new Point(20.24611, 110.2789),
  659.             new Point(20.2336, 109.9244),
  660.             new Point(20.4318, 110.0069),
  661.             new Point(20.92416, 109.6629),
  662.             new Point(21.44694, 109.9411),
  663.             new Point(21.50569, 109.6605),
  664.             new Point(21.72333, 109.5733),
  665.             new Point(21.49499, 109.5344),
  666.             new Point(21.39666, 109.1428),
  667.             new Point(21.58305, 109.1375),
  668.             new Point(21.61611, 108.911),
  669.             new Point(21.79889, 108.8702),
  670.             new Point(21.59888, 108.7403),
  671.             new Point(21.93562, 108.4692),
  672.             new Point(21.59014, 108.5125),
  673.             new Point(21.68999, 108.3336),
  674.             new Point(21.51444, 108.2447),
  675.             new Point(21.54241, 107.99),
  676.             new Point(21.66694, 107.7831),
  677.             new Point(21.60526, 107.3627),
  678.             new Point(22.03083, 106.6933),
  679.             new Point(22.45682, 106.5517),
  680.             new Point(22.76389, 106.7875),
  681.             new Point(22.86694, 106.7029),
  682.             new Point(22.91253, 105.8771),
  683.             new Point(23.32416, 105.3587),
  684.             new Point(23.18027, 104.9075),
  685.             new Point(22.81805, 104.7319),
  686.             new Point(22.6875, 104.3747),
  687.             new Point(22.79812, 104.1113),
  688.             new Point(22.50387, 103.9687),
  689.             new Point(22.78287, 103.6538),
  690.             new Point(22.58436, 103.5224),
  691.             new Point(22.79451, 103.3337),
  692.             new Point(22.43652, 103.0304),
  693.             new Point(22.77187, 102.4744),
  694.             new Point(22.39629, 102.1407),
  695.             new Point(22.49777, 101.7415),
  696.             new Point(22.20916, 101.5744),
  697.             new Point(21.83444, 101.7653),
  698.             new Point(21.14451, 101.786),
  699.             new Point(21.17687, 101.2919),
  700.             new Point(21.57264, 101.1482),
  701.             new Point(21.76903, 101.099),
  702.             new Point(21.47694, 100.6397),
  703.             new Point(21.43546, 100.2057),
  704.             new Point(21.72555, 99.97763),
  705.             new Point(22.05018, 99.95741),
  706.             new Point(22.15592, 99.16785),
  707.             new Point(22.93659, 99.56484),
  708.             new Point(23.08204, 99.5113),
  709.             new Point(23.18916, 98.92747),
  710.             new Point(23.97076, 98.67991),
  711.             new Point(24.16007, 98.89073),
  712.             new Point(23.92999, 97.54762),
  713.             new Point(24.26055, 97.7593),
  714.             new Point(24.47666, 97.54305),
  715.             new Point(24.73992, 97.55255),
  716.             new Point(25.61527, 98.19109),
  717.             new Point(25.56944, 98.36137),
  718.             new Point(25.85597, 98.7104),
  719.             new Point(26.12527, 98.56944),
  720.             new Point(26.18472, 98.73109),
  721.             new Point(26.79166, 98.77777),
  722.             new Point(27.52972, 98.69699),
  723.             new Point(27.6725, 98.45888),
  724.             new Point(27.54014, 98.31992),
  725.             new Point(28.14889, 98.14499),
  726.             new Point(28.54652, 97.55887),
  727.             new Point(28.22277, 97.34888),
  728.             new Point(28.46749, 96.65387),
  729.             new Point(28.35111, 96.40193),
  730.             new Point(28.525, 96.34027),
  731.             new Point(28.79569, 96.61373),
  732.             new Point(29.05666, 96.47083),
  733.             new Point(28.90138, 96.17532),
  734.             new Point(29.05972, 96.14888),
  735.             new Point(29.25757, 96.39172),
  736.             new Point(29.46444, 96.08315),
  737.             new Point(29.03527, 95.38777),
  738.             new Point(29.33346, 94.64751),
  739.             new Point(29.07348, 94.23456),
  740.             new Point(28.6692, 93.96172),
  741.             new Point(28.61876, 93.35194),
  742.             new Point(28.3193, 93.22205),
  743.             new Point(28.1419, 92.71044),
  744.             new Point(27.86194, 92.54498),
  745.             new Point(27.76472, 91.65776),
  746.             new Point(27.945, 91.66277),
  747.             new Point(28.08111, 91.30138),
  748.             new Point(27.96999, 91.08693),
  749.             new Point(28.07958, 90.3765),
  750.             new Point(28.24257, 90.38898),
  751.             new Point(28.32369, 89.99819),
  752.             new Point(28.05777, 89.48749),
  753.             new Point(27.32083, 88.91693)
  754.     };
  755.  
  756.     //Taiwan
  757.     private static final Point[] TAIWAN = new Point[]{
  758.             new Point(25.13474, 121.4441),
  759.             new Point(25.28361, 121.5632),
  760.             new Point(25.00722, 122.0004),
  761.             new Point(24.85028, 121.8182),
  762.             new Point(24.47638, 121.8397),
  763.             new Point(23.0875, 121.3556),
  764.             new Point(21.92791, 120.7196),
  765.             new Point(22.31277, 120.6103),
  766.             new Point(22.54044, 120.3071),
  767.             new Point(23.04437, 120.0539),
  768.             new Point(23.61708, 120.1112),
  769.             new Point(25.00166, 121.0017),
  770.             new Point(25.13474, 121.4441)
  771.     };
  772.  
  773.     //Hainan
  774.     private static final Point[] HAINAN = new Point[]{
  775.             new Point(19.52888, 110.855),
  776.             new Point(19.16761, 110.4832),
  777.             new Point(18.80083, 110.5255),
  778.             new Point(18.3852, 110.0503),
  779.             new Point(18.39152, 109.7594),
  780.             new Point(18.19777, 109.7036),
  781.             new Point(18.50562, 108.6871),
  782.             new Point(19.28028, 108.6283),
  783.             new Point(19.76, 109.2939),
  784.             new Point(19.7236, 109.1653),
  785.             new Point(19.89972, 109.2572),
  786.             new Point(19.82861, 109.4658),
  787.             new Point(19.99389, 109.6108),
  788.             new Point(20.13361, 110.6655),
  789.             new Point(19.97861, 110.9425),
  790.             new Point(19.63829, 111.0215),
  791.             new Point(19.52888, 110.855)
  792.     };
  793.  
  794.     //Chongming
  795.     private static final Point[] CHONGMING = new Point[]{
  796.             new Point(31.80054, 121.2039),
  797.             new Point(31.49972, 121.8736),
  798.             new Point(31.53111, 121.5464),
  799.             new Point(31.80054, 121.2039)
  800.     };
  801.     //endregion
  802.  
  803.     /**
  804.      * 中国行政边界的WGS84坐标数据,
  805.      * 光线投射算法 (Ray casting algorithm) 获得,
  806.      * 沿海、国界周边地区可能会有误差,更高精度需要调整坐标点
  807.      */
  808.     private static final List<Point[]> CHINA_POLYGON = new ArrayList<>();
  809.  
  810.     static {
  811.         CHINA_POLYGON.add(MAINLAND);
  812.         CHINA_POLYGON.add(TAIWAN);
  813.         CHINA_POLYGON.add(HAINAN);
  814.         CHINA_POLYGON.add(CHONGMING);
  815.     }
  816.    
  817. }
上次由 BG6RSH 在 周一 10月 03, 2022 7:53 pm,总共编辑 3 次。
BG6RSH
帖子: 89
注册时间: 周日 6月 23, 2019 12:00 pm

Re: traccar-server源代码编译环境搭建

帖子 BG6RSH »

5、AmapGeocoder.java
  1. Index: src/main/java/org/traccar/geocoder/AmapGeocoder.java
  2. IDEA additional info:
  3. Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
  4. <+>UTF-8
  5. ===================================================================
  6. --- src/main/java/org/traccar/geocoder/AmapGeocoder.java    (date 1585677242157)
  7. +++ src/main/java/org/traccar/geocoder/AmapGeocoder.java    (date 1585677242157)
  8. @@ -0,0 +1,97 @@
  9. +/*
  10. + * Copyright 2020 Bg6rsh (admin@tansoo.cn)
  11. + *
  12. + * Licensed under the Apache License, Version 2.0 (the "License");
  13. + * you may not use this file except in compliance with the License.
  14. + * You may obtain a copy of the License at
  15. + *
  16. + *     http://www.apache.org/licenses/LICENSE-2.0
  17. + *
  18. + * Unless required by applicable law or agreed to in writing, software
  19. + * distributed under the License is distributed on an "AS IS" BASIS,
  20. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  21. + * See the License for the specific language governing permissions and
  22. + * limitations under the License.
  23. + */
  24. +package org.traccar.geocoder;
  25. +
  26. +import javax.json.*;
  27. +import java.io.StringReader;
  28. +
  29. +public class AmapGeocoder extends JsonGeocoder {
  30. +
  31. +    private static String formatUrl(String url, String key) {
  32. +        if (url == null) {
  33. +            url = "https://restapi.amap.com/v3/geocode/regeo";
  34. +        }
  35. +        url += "?location=%f,%f&roadlevel=0&key=" + key;
  36. +
  37. +        return url;
  38. +    }
  39. +
  40. +    public AmapGeocoder(String url, String key, int cacheSize, AddressFormat addressFormat) {
  41. +        super(formatUrl(url, key), cacheSize, addressFormat);
  42. +    }
  43. +
  44. +    @Override
  45. +    public Address parseAddress(JsonObject json) {
  46. +        Address address = new Address();
  47. +        try {
  48. +            String formatted_address = json.getJsonObject("regeocode").getString("formatted_address");
  49. +            address.setFormattedAddress(formatted_address);
  50. +        }catch (Exception e) {
  51. +            return null;
  52. +        }
  53. +        return address;
  54. +  /*
  55. +        String json_str = json.toString();
  56. +        json_str = json_str.replaceAll("\\[\\]","\"\"");
  57. +        JsonReader reader = Json.createReader(new StringReader(json_str));
  58. +        JsonObject personObject = reader.readObject();
  59. +        reader.close();
  60. +
  61. +        if(personObject.getString("status").equals("1")) {
  62. +            JsonObject regeocodeObject = personObject.getJsonObject("regeocode");
  63. +
  64. +            if (regeocodeObject != null) {
  65. +                Address address = new Address();
  66. +                address.setFormattedAddress("%f");
  67. +
  68. +                if (regeocodeObject.containsKey("formatted_address")) {
  69. +                    String str_format_address = regeocodeObject.getString("formatted_address");
  70. +                    address.setFormattedAddress(str_format_address);
  71. +                }
  72. +
  73. +                JsonObject addressObject = regeocodeObject.getJsonObject("addressComponent");
  74. +
  75. +                if (addressObject != null) {
  76. +                    if (addressObject.containsKey("adcode"))
  77. +                        address.setPostcode(addressObject.getString("adcode"));
  78. +
  79. +                    if (addressObject.containsKey("city"))
  80. +                        address.setSettlement(addressObject.getString("city"));
  81. +
  82. +                    if (addressObject.containsKey("province"))
  83. +                        address.setState(addressObject.getString("province"));
  84. +
  85. +                    if (addressObject.containsKey("district"))
  86. +                        address.setDistrict(addressObject.getString("district"));
  87. +
  88. +                    if (addressObject.containsKey("country"))
  89. +                        address.setCountry(addressObject.getString("country"));
  90. +
  91. +                    JsonObject streetNumber = addressObject.getJsonObject("streetNumber");
  92. +                    if (streetNumber != null) {
  93. +                        if (streetNumber.containsKey("street"))
  94. +                            address.setStreet(streetNumber.getString("street"));
  95. +
  96. +                        if (streetNumber.containsKey("number"))
  97. +                            address.setHouse(streetNumber.getString("number"));
  98. +                    }
  99. +                }
  100. +                return address;
  101. +            }
  102. +        }
  103. +        return null;*/
  104. +    }
  105. +}
  106. \ No newline at end of file
回复