Selaa lähdekoodia

优化地址定位逻辑

woody 1 vuosi sitten
vanhempi
commit
ef6d3f1288

+ 1 - 1
framework-location/src/main/java/com/chelvc/framework/location/Area.java

@@ -23,7 +23,7 @@ public class Area implements Serializable {
     /**
      * 区域标识
      */
-    private Long id;
+    private Integer id;
 
     /**
      * 区域名称

+ 9 - 0
framework-location/src/main/java/com/chelvc/framework/location/LocationHandler.java

@@ -22,4 +22,13 @@ public interface LocationHandler {
      * @return 地址信息
      */
     Address location2address(String location);
+
+    /**
+     * 根据经纬度定位地址
+     *
+     * @param longitude 经度
+     * @param latitude  维度
+     * @return 地址信息
+     */
+    Address location2address(double longitude, double latitude);
 }

+ 8 - 3
framework-location/src/main/java/com/chelvc/framework/location/support/TencentLocationHandler.java

@@ -84,14 +84,14 @@ public class TencentLocationHandler implements LocationHandler {
                         .filter(name -> !StringUtils.isEmpty(name)).collect(Collectors.joining("·"))
         );
         address.setProvince(
-                Area.builder().id((long) region.getProvince().getCode()).name(location.getProvince()).build()
+                Area.builder().id(region.getProvince().getCode()).name(location.getProvince()).build()
         );
         Region city = region.getCity();
         if (city != null) {
-            address.setCity(Area.builder().id((long) city.getCode()).name(location.getCity()).build());
+            address.setCity(Area.builder().id(city.getCode()).name(location.getCity()).build());
         }
         if (region.getType() == Region.Type.DISTRICT) {
-            address.setDistrict(Area.builder().id((long) region.getCode()).name(location.getDistrict()).build());
+            address.setDistrict(Area.builder().id(region.getCode()).name(location.getDistrict()).build());
         }
         return address;
     }
@@ -105,4 +105,9 @@ public class TencentLocationHandler implements LocationHandler {
     public Address location2address(@NonNull String location) {
         return this.execute(LOCATION2ADDRESS_URL, location);
     }
+
+    @Override
+    public Address location2address(double longitude, double latitude) {
+        return this.location2address(longitude + "," + latitude);
+    }
 }