|
|
@@ -1,12 +1,15 @@
|
|
|
package com.qingjian.common.utils;
|
|
|
|
|
|
+import cn.hutool.core.io.FileUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.qingjian.common.constants.PathConst;
|
|
|
-import com.sun.jna.Memory;
|
|
|
-import com.sun.jna.Pointer;
|
|
|
import com.sun.jna.ptr.DoubleByReference;
|
|
|
-import com.sun.jna.ptr.IntByReference;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
import java.nio.file.Files;
|
|
|
+import java.nio.file.Path;
|
|
|
+import java.nio.file.Paths;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
|
|
|
/**
|
|
|
@@ -18,9 +21,10 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
*
|
|
|
* @author cc
|
|
|
*/
|
|
|
+@Slf4j
|
|
|
public class TowerUtils {
|
|
|
|
|
|
- private static final int ADDRESS_BUFFER_SIZE = 1024;
|
|
|
+ private static final int ADDRESS_BUFFER_SIZE = 2048;
|
|
|
private static final AtomicBoolean FLAG = new AtomicBoolean(false);
|
|
|
|
|
|
/**
|
|
|
@@ -41,10 +45,25 @@ public class TowerUtils {
|
|
|
* </p>
|
|
|
*/
|
|
|
public static void init() {
|
|
|
- if (Files.exists(PathConst.CELL_TOWER_PATH_BIN)) {
|
|
|
- CellDll.INSTANCE_DLL.cell_init(PathConst.CELL_TOWER_PATH_BIN.toString());
|
|
|
+ String cellLocal = SystemConfManager.INSTANCE.getCellLocal();
|
|
|
+ if (StrUtil.isEmpty(cellLocal)) {
|
|
|
+ log.info("请先设置基站数据库路径!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Path path = Paths.get(cellLocal);
|
|
|
+ if (Files.exists(path)) {
|
|
|
+ String name = FileUtil.getName(path);
|
|
|
+ if(!name.equalsIgnoreCase("cellinfo.bin")){
|
|
|
+ log.info("基站数据库文件名不正确!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Path parent = path.getParent();
|
|
|
+ CellDll.INSTANCE_DLL.cell_init(parent.toString());
|
|
|
FLAG.set(true);
|
|
|
+ log.info("基站数据库路径已经加载!");
|
|
|
+ return;
|
|
|
}
|
|
|
+ log.info("基站数据库路径不存在!");
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -66,6 +85,7 @@ public class TowerUtils {
|
|
|
* - obj[2]: 覆盖半径(米)
|
|
|
* - obj[3]: 详细地址描述
|
|
|
* 示例调用:CellUtils.getCells(460, 0, 1, 2)
|
|
|
+ * getCells(460, 0, 32796, 64265);
|
|
|
* <p>
|
|
|
* 返回示例:[35.994564, 12.468795, 123, "北京市朝阳xxx4号楼;望京街xx163米"]
|
|
|
* </p>
|
|
|
@@ -79,15 +99,15 @@ public class TowerUtils {
|
|
|
// 创建用于接收查询结果的引用对象
|
|
|
DoubleByReference latitude = new DoubleByReference(0.0); // WGS84 纬度
|
|
|
DoubleByReference longitude = new DoubleByReference(0.0); // WGS84 经度
|
|
|
- DoubleByReference valid = new DoubleByReference(0.0); // 原生库要求的有效性输出参数
|
|
|
- IntByReference radius = new IntByReference(0); // 覆盖半径
|
|
|
- IntByReference date = new IntByReference(0); // 原生库要求的日期输出参数
|
|
|
+ byte[] combined = new byte[ADDRESS_BUFFER_SIZE];
|
|
|
+
|
|
|
|
|
|
// 调用本地库查询基站信息
|
|
|
- int queryResult = CellDll.INSTANCE_DLL.cell_query(mcc, mnc, lac, ci, latitude, longitude, radius, date, valid);
|
|
|
+ int queryResult = CellDll.INSTANCE_DLL.cell_query_combined(mcc, mnc, lac, ci,
|
|
|
+ CellDll.COORD_WGS84, latitude, longitude, combined, combined.length);
|
|
|
|
|
|
// 如果查询失败,返回空数组
|
|
|
- if (queryResult == 0) {
|
|
|
+ if (queryResult != 0) {
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
@@ -97,28 +117,10 @@ public class TowerUtils {
|
|
|
//double[] bd09 = CoordinateTransform.transformWGS84ToBD09(sourceLongitude, sourceLatitude);
|
|
|
result[0] = sourceLatitude;
|
|
|
result[1] = sourceLongitude;
|
|
|
- result[2] = radius.getValue();
|
|
|
+ result[2] = 0;
|
|
|
|
|
|
// 逆地理编码依旧使用原始 WGS84 坐标,保持与现有 native 接口行为一致。
|
|
|
- result[3] = reverseGeocode(sourceLatitude, sourceLongitude);
|
|
|
-
|
|
|
+ result[3] = StrUtil.str(combined, StandardCharsets.UTF_8);
|
|
|
return result;
|
|
|
}
|
|
|
-
|
|
|
- /**
|
|
|
- * 调用原生库根据 WGS84 坐标获取地址描述。
|
|
|
- *
|
|
|
- * @param latitude WGS84 纬度
|
|
|
- * @param longitude WGS84 经度
|
|
|
- * @return 地址描述
|
|
|
- */
|
|
|
- private static String reverseGeocode(double latitude, double longitude) {
|
|
|
- Pointer addressBuffer = new Memory(ADDRESS_BUFFER_SIZE);
|
|
|
- try {
|
|
|
- CellDll.INSTANCE_DLL.regeo_simple(addressBuffer, latitude, longitude);
|
|
|
- return addressBuffer.getString(0, "utf-8");
|
|
|
- } finally {
|
|
|
- addressBuffer.clear(ADDRESS_BUFFER_SIZE);
|
|
|
- }
|
|
|
- }
|
|
|
}
|