From 40a806329ce08d5f50795cf965ef773aa48fdd3e Mon Sep 17 00:00:00 2001 From: 648540858 <456panlinlin> Date: 星期五, 15 四月 2022 09:37:33 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/wvp-28181-2.0' into map --- src/main/java/com/genersoft/iot/vmp/utils/GpsUtil.java | 91 +++++++++++++++++++++++++-------------------- 1 files changed, 50 insertions(+), 41 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/utils/GpsUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/GpsUtil.java index 53e6a61..47f9421 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/GpsUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/GpsUtil.java @@ -17,48 +17,57 @@ public static BaiduPoint Wgs84ToBd09(String xx, String yy) { - try { - Socket s = new Socket("api.map.baidu.com", 80); - BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream(), "UTF-8")); - OutputStream out = s.getOutputStream(); - StringBuffer sb = new StringBuffer("GET /ag/coord/convert?from=0&to=4"); - sb.append("&x=" + xx + "&y=" + yy); - sb.append("&callback=BMap.Convertor.cbk_3976 HTTP/1.1\r\n"); - sb.append("User-Agent: Java/1.6.0_20\r\n"); - sb.append("Host: api.map.baidu.com:80\r\n"); - sb.append("Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n"); - sb.append("Connection: Close\r\n"); - sb.append("\r\n"); - out.write(sb.toString().getBytes()); - String json = ""; - String tmp = ""; - while ((tmp = br.readLine()) != null) { - // logger.info(tmp); - json += tmp; - } +// try { +// Socket s = new Socket("api.map.baidu.com", 80); +// BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream(), "UTF-8")); +// OutputStream out = s.getOutputStream(); +// StringBuffer sb = new StringBuffer("GET /ag/coord/convert?from=0&to=4"); +// sb.append("&x=" + xx + "&y=" + yy); +// sb.append("&callback=BMap.Convertor.cbk_3976 HTTP/1.1\r\n"); +// sb.append("User-Agent: Java/1.6.0_20\r\n"); +// sb.append("Host: api.map.baidu.com:80\r\n"); +// sb.append("Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2\r\n"); +// sb.append("Connection: Close\r\n"); +// sb.append("\r\n"); +// out.write(sb.toString().getBytes()); +// String json = ""; +// String tmp = ""; +// while ((tmp = br.readLine()) != null) { +// // logger.info(tmp); +// json += tmp; +// } +// +// s.close(); +// int start = json.indexOf("cbk_3976"); +// int end = json.lastIndexOf("}"); +// if (start != -1 && end != -1 && json.contains("\"x\":\"")) { +// json = json.substring(start, end); +// String[] point = json.split(","); +// String x = point[1].split(":")[1].replace("\"", ""); +// String y = point[2].split(":")[1].replace("\"", ""); +// BaiduPoint bdPoint= new BaiduPoint(); +// bdPoint.setBdLng(new String(decode(x))); +// bdPoint.setBdLat(new String(decode(y))); +// return bdPoint; +// //return (new String(decode(x)) + "," + new String(decode(y))); +// } else { +// logger.info("gps鍧愭爣鏃犳晥锛侊紒"); +// } +// out.close(); +// br.close(); +// } catch (Exception e) { +// e.printStackTrace(); +// } - s.close(); - int start = json.indexOf("cbk_3976"); - int end = json.lastIndexOf("}"); - if (start != -1 && end != -1 && json.contains("\"x\":\"")) { - json = json.substring(start, end); - String[] point = json.split(","); - String x = point[1].split(":")[1].replace("\"", ""); - String y = point[2].split(":")[1].replace("\"", ""); - BaiduPoint bdPoint= new BaiduPoint(); - bdPoint.setBdLng(new String(decode(x))); - bdPoint.setBdLat(new String(decode(y))); - return bdPoint; - //return (new String(decode(x)) + "," + new String(decode(y))); - } else { - logger.info("gps鍧愭爣鏃犳晥锛侊紒"); - } - out.close(); - br.close(); - } catch (Exception e) { - e.printStackTrace(); - } - return null; + + double lng = Double.parseDouble(xx); + double lat = Double.parseDouble(yy); + Double[] gcj02 = Coordtransform.WGS84ToGCJ02(lng, lat); + Double[] doubles = Coordtransform.GCJ02ToBD09(gcj02[0], gcj02[1]); + BaiduPoint bdPoint= new BaiduPoint(); + bdPoint.setBdLng(doubles[0] + ""); + bdPoint.setBdLat(doubles[1] + ""); + return bdPoint; } /** -- Gitblit v1.8.0