main
parent
9d0e9a952b
commit
02b803730c
|
|
@ -66,7 +66,7 @@ public class AppCircleVo implements Serializable {
|
|||
private Integer isAdmin;
|
||||
|
||||
@ApiModelProperty(value = "距离")
|
||||
private String distance;
|
||||
private Integer distance;
|
||||
|
||||
@ApiModelProperty(value = "途经位置经纬度列表")
|
||||
private List<AppCircleAddress> addressVoList;
|
||||
|
|
|
|||
|
|
@ -151,6 +151,7 @@ public class AppCircleServiceImpl implements IAppCircleService {
|
|||
PageHelper.startPage(pageSize, limit);
|
||||
PageInfo<AppCircleVo> page = new PageInfo(appCircleMapper.recommendCircleList(appCircle));
|
||||
List<AppCircleVo> list = page.getList();
|
||||
List<AppCircleVo> appCircleVos = new ArrayList<>();
|
||||
for (AppCircleVo circle : list) {
|
||||
// 计算位置
|
||||
if (circle.getType() == 3) {
|
||||
|
|
@ -164,29 +165,38 @@ public class AppCircleServiceImpl implements IAppCircleService {
|
|||
);
|
||||
circle.setAddressVoList(appCircleAddresses);
|
||||
}
|
||||
if (circle.getDistance() <= 5000) {
|
||||
appCircleVos.add(circle);
|
||||
}
|
||||
}
|
||||
}
|
||||
page.setList(list);
|
||||
if (appCircle.getType() == 3) {
|
||||
page.setList(appCircleVos);
|
||||
} else {
|
||||
page.setList(list);
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
private static final double EARTH_RADIUS = 6371000; // 地球半径,单位米
|
||||
|
||||
public static String calculateDistance(double lat1, double lon1, double lat2, double lon2) {
|
||||
double latDistance = toRadians(lat2 - lat1);
|
||||
double lonDistance = toRadians(lon2 - lon2);
|
||||
double a = sin(latDistance / 2) * sin(latDistance / 2) +
|
||||
cos(toRadians(lat1)) * cos(toRadians(lat2)) *
|
||||
sin(lonDistance / 2) * sin(lonDistance / 2);
|
||||
double c = 2 * atan2(sqrt(a), sqrt(1 - a));
|
||||
public static Integer calculateDistance(double lat1, double lon1, double lat2, double lon2) {
|
||||
double phi1 = Math.toRadians(lat1);
|
||||
double phi2 = Math.toRadians(lat2);
|
||||
double deltaPhi = Math.toRadians(lat2 - lat1);
|
||||
double deltaLambda = Math.toRadians(lon2 - lon1);
|
||||
|
||||
double a = Math.sin(deltaPhi / 2) * Math.sin(deltaPhi / 2) +
|
||||
Math.cos(phi1) * Math.cos(phi2) *
|
||||
Math.sin(deltaLambda / 2) * Math.sin(deltaLambda / 2);
|
||||
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
|
||||
String d = (EARTH_RADIUS * c) + "";
|
||||
d = d.substring(0,d.indexOf("."));
|
||||
return d;
|
||||
return Integer.valueOf(d.substring(0,d.indexOf(".")));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// 示例:计算从当前地址(纬度40.7128,经度-74.0060)到另一个地址的距离
|
||||
String distance = calculateDistance(31.191648
|
||||
Integer distance = calculateDistance(31.191648
|
||||
, 121.313248, 31.183105
|
||||
, 121.263785);
|
||||
System.out.println("距离: " + distance + " 米");
|
||||
|
|
|
|||
Loading…
Reference in New Issue