房屋价值评估接口(地址版)增加经纬度估值
This commit is contained in:
@@ -1,13 +1,16 @@
|
|||||||
package com.fangjia.core.util;
|
package com.fangjia.core.util;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class GeoUtils {
|
public class GeoUtils {
|
||||||
|
|
||||||
public static final String LAT ="lat";
|
public static final String LAT = "lat";
|
||||||
|
|
||||||
public static final String LNG ="lng";
|
public static final String LNG = "lng";
|
||||||
|
|
||||||
public enum GaussSphere {
|
public enum GaussSphere {
|
||||||
Beijing54, Xian80, WGS84,
|
Beijing54, Xian80, WGS84,
|
||||||
@@ -34,10 +37,8 @@ public class GeoUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param raidus
|
* @param raidus 单位米
|
||||||
* 单位米
|
* @return minLat, maxLat, minLng,maxLng
|
||||||
*
|
|
||||||
* @return minLat,maxLat, minLng,maxLng
|
|
||||||
*/
|
*/
|
||||||
public static double[] getAround(double lat, double lng, double radius) {
|
public static double[] getAround(double lat, double lng, double radius) {
|
||||||
Double latitude = lat;
|
Double latitude = lat;
|
||||||
@@ -55,20 +56,16 @@ public class GeoUtils {
|
|||||||
Double radiusLng = dpmLng * raidusMile;
|
Double radiusLng = dpmLng * raidusMile;
|
||||||
Double minLng = longitude - radiusLng;
|
Double minLng = longitude - radiusLng;
|
||||||
Double maxLng = longitude + radiusLng;
|
Double maxLng = longitude + radiusLng;
|
||||||
return new double[] { minLat, maxLat, minLng, maxLng };
|
return new double[]{minLat, maxLat, minLng, maxLng};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据给定的经纬度、距离、角度,计算对应的经纬度
|
* 根据给定的经纬度、距离、角度,计算对应的经纬度
|
||||||
*
|
*
|
||||||
* @param Lat
|
* @param Lat 原始纬度
|
||||||
* 原始纬度
|
* @param Lon 原始精度
|
||||||
* @param Lon
|
* @param distance 距离(米)
|
||||||
* 原始精度
|
* @param angle , 90: right, 180: down
|
||||||
* @param distance
|
|
||||||
* 距离(米)
|
|
||||||
* @param angle
|
|
||||||
* , 90: right, 180: down
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static double[] getLatLon(double Lon, double Lat, int distance, double angle) {
|
public static double[] getLatLon(double Lon, double Lat, int distance, double angle) {
|
||||||
@@ -78,7 +75,7 @@ public class GeoUtils {
|
|||||||
double lon1 = (dx / edd(Lat) + eadLon(Lon)) * 180 / Math.PI;
|
double lon1 = (dx / edd(Lat) + eadLon(Lon)) * 180 / Math.PI;
|
||||||
double lat1 = (dy / ecc(Lat) + radLat(Lat)) * 180 / Math.PI;
|
double lat1 = (dy / ecc(Lat) + radLat(Lat)) * 180 / Math.PI;
|
||||||
|
|
||||||
return new double[] { lon1, lat1 };
|
return new double[]{lon1, lat1};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -123,23 +120,26 @@ public class GeoUtils {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 百度转 wgs84
|
* 百度转 wgs84
|
||||||
|
*
|
||||||
* @param bd_lat
|
* @param bd_lat
|
||||||
* @param bd_lng
|
* @param bd_lng
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Map<String, Double> bd09ToGps84(double bd_lat, double bd_lng) {
|
public static Map<String, Double> bd09ToGps84(double bd_lat, double bd_lng) {
|
||||||
Map<String, Double> gps = bd09ToGcj02(bd_lat,bd_lng);
|
Map<String, Double> gps = bd09ToGcj02(bd_lat, bd_lng);
|
||||||
return gcjToGps84(gps.get(LAT),gps.get(LNG));
|
return gcjToGps84(gps.get(LAT), gps.get(LNG));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wgs84 转百度
|
* wgs84 转百度
|
||||||
|
*
|
||||||
* @param bd_lat
|
* @param bd_lat
|
||||||
* @param bd_lng
|
* @param bd_lng
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static Map<String, Double> Gps84Tobd09(double lat, double lng) {
|
public static Map<String, Double> Gps84Tobd09(double lat, double lng) {
|
||||||
Map<String, Double> gps = gps84ToGcj02(lat,lng);
|
Map<String, Double> gps = gps84ToGcj02(lat, lng);
|
||||||
return gcj02ToBd09(gps.get(LAT),gps.get(LNG));
|
return gcj02ToBd09(gps.get(LAT), gps.get(LNG));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -258,8 +258,72 @@ public class GeoUtils {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args){
|
public static Map<String, String> parserByGaode(String city, String address) {
|
||||||
Map<String, Double> location = gps84ToGcj02(31.218024629574998,121.36562884455);
|
Map<String, String> params = new HashMap<String, String>();
|
||||||
System.out.println(location.toString());
|
params.put("city", city);
|
||||||
|
params.put("address", address);
|
||||||
|
String content;
|
||||||
|
|
||||||
|
try {
|
||||||
|
params.put("key", getGaodeKey("v3/geocode/geo"));
|
||||||
|
content = new HttpRequest().get("https://restapi.amap.com/v3/geocode/geo", params, "utf-8");
|
||||||
|
} catch (Exception e) {
|
||||||
|
params.put("key", getGaodeKey("v3/geocode/geo"));
|
||||||
|
try {
|
||||||
|
content = new HttpRequest().get("https://restapi.amap.com/v3/geocode/geo", params, "utf-8");
|
||||||
|
} catch (HttpRequestException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONObject json = new JSONObject(content);
|
||||||
|
if (json != null && "OK".equals(json.optString("info"))) {
|
||||||
|
JSONArray ret = json.getJSONArray("geocodes");
|
||||||
|
if (ret.length() > 0) {
|
||||||
|
JSONObject firstResult = ret.getJSONObject(0);
|
||||||
|
String str = firstResult.getString("location");
|
||||||
|
String cityA = firstResult.getString("city");
|
||||||
|
String district = firstResult.getString("district");
|
||||||
|
JSONArray township = firstResult.getJSONArray("township");
|
||||||
|
String level = firstResult.getString("level");
|
||||||
|
String[] arrs = str.split(",");
|
||||||
|
Map<String, String> result = new HashMap<String, String>();
|
||||||
|
result.put("lng", arrs[0]);
|
||||||
|
result.put("lat", arrs[1]);
|
||||||
|
result.put("level", level);
|
||||||
|
result.put("city", cityA);
|
||||||
|
result.put("district", district);
|
||||||
|
if (township.length() > 0) {
|
||||||
|
result.put("town", township.toString());
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
} else if (json != null && "10044".equals(json.optString("infocode"))) {
|
||||||
|
System.exit(1);
|
||||||
|
} else if (json != null && "10004".equals(json.optString("infocode"))) {
|
||||||
|
// 开发者的单位时间内(1分钟)访问量超限,被系统自动封停,下一分钟自动解封。
|
||||||
|
try {
|
||||||
|
Thread.sleep(60000);
|
||||||
|
} catch (InterruptedException ie) {
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
} else if (json != null && "10017".equals(json.optString("infocode"))) {
|
||||||
|
// 所请求的资源不可用
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null; // 如果没有返回值,可以根据需要处理
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getGaodeKey(String endpoint) {
|
||||||
|
// 实现获取高德 API key 的逻辑
|
||||||
|
return "8796b9dfb3889b57c38e2fff1b7e51bd";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Map<String, Double> location = gps84ToGcj02(31.218024629574998,121.36562884455);
|
||||||
|
// System.out.println(location.toString());
|
||||||
|
Map<String, String> result = parserByGaode("上海", "新泾三村");
|
||||||
|
System.out.println(result.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+28
-1
@@ -180,6 +180,8 @@ public class PropertyController {
|
|||||||
private static final int DEFAULT_PAGE_SIZE = 20;
|
private static final int DEFAULT_PAGE_SIZE = 20;
|
||||||
private static final int DEFAULT_HOUSE_COUNT = 5;
|
private static final int DEFAULT_HOUSE_COUNT = 5;
|
||||||
private static final String[] PROPERTY_SEARCH_API_FIELDS = {"address", "city", "region", "name", "lat2", "lng2", "lat", "lng", "block", "estateType2", "addrAlias", "alias"};
|
private static final String[] PROPERTY_SEARCH_API_FIELDS = {"address", "city", "region", "name", "lat2", "lng2", "lat", "lng", "block", "estateType2", "addrAlias", "alias"};
|
||||||
|
|
||||||
|
private static final List<String> GAODE_LEVEL = Arrays.asList("兴趣点", "门牌号", "单元号", "楼层", "房间", "门址", "住宅区");
|
||||||
static final int BAI_DU_GEO = 1;// 百度系坐标
|
static final int BAI_DU_GEO = 1;// 百度系坐标
|
||||||
static final int GAO_DE_GEO = 2;// 高德系坐标
|
static final int GAO_DE_GEO = 2;// 高德系坐标
|
||||||
|
|
||||||
@@ -1622,7 +1624,32 @@ public class PropertyController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (district == null) {
|
if (district == null) {
|
||||||
|
//加上高德获取经纬度 和 根据经纬度估值
|
||||||
|
Map<String, String> map = GeoUtils.parserByGaode(model.getCity(), model.getAddress());
|
||||||
|
if (map.containsKey("level") && GAODE_LEVEL.contains(map.get("level"))
|
||||||
|
&& map.containsKey("lng") && map.containsKey("lat")) {
|
||||||
|
String location = map.get("lng") + "," + map.get("lat");
|
||||||
|
HttpRequest httpRequest = new HttpRequest();
|
||||||
|
JSONObject json = null;
|
||||||
|
Map<String, String> param = new HashMap<String, String>();
|
||||||
|
param.put("location", location);
|
||||||
|
param.put("area", String.valueOf(model.getSize()));
|
||||||
|
try {
|
||||||
|
json = httpRequest.getJsonContent("http://192.168.0.100:30020/avmWeb/avmAnn", param, "UTF-8");
|
||||||
|
if (json.containsKey("msg") && "成功".equals(json.getString("msg"))) {
|
||||||
|
HashMap<String, String> resultMap = new HashMap<String, String>();
|
||||||
|
resultMap.put("avgPrice",json.getString("unitPrice"));
|
||||||
|
resultMap.put("totalPrice",json.getString("totalPrice"));
|
||||||
|
mav.setModel(BasicModel.buildOKModel().setResult(resultMap));
|
||||||
|
} else {
|
||||||
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
||||||
|
}
|
||||||
|
} catch (HttpRequestException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mav.setModel(BasicModel.buildBadRequestModel("该地址不支持估价!"));
|
||||||
|
}
|
||||||
return mav;
|
return mav;
|
||||||
}
|
}
|
||||||
model.setDistrict(district.getRegion());
|
model.setDistrict(district.getRegion());
|
||||||
@@ -2508,7 +2535,7 @@ public class PropertyController {
|
|||||||
}
|
}
|
||||||
Date startDate = DateUtil.add(new Date(), Calendar.MONTH, -model.getPeriodCount());
|
Date startDate = DateUtil.add(new Date(), Calendar.MONTH, -model.getPeriodCount());
|
||||||
|
|
||||||
List<SqmetreRent> sqmetreRents = sqmetreRentService.findSqmetreRents(RegionData.formatCity(model.getCity()), RegionData.formatRegion(model.getCity(),model.getDistrict()), model.getName(), model.getCat(), startDate, null);
|
List<SqmetreRent> sqmetreRents = sqmetreRentService.findSqmetreRents(RegionData.formatCity(model.getCity()), RegionData.formatRegion(model.getCity(), model.getDistrict()), model.getName(), model.getCat(), startDate, null);
|
||||||
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(model.getPeriodCount());
|
List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(model.getPeriodCount());
|
||||||
|
|
||||||
for (SqmetreRent sqmetreRent : sqmetreRents) {
|
for (SqmetreRent sqmetreRent : sqmetreRents) {
|
||||||
|
|||||||
Reference in New Issue
Block a user