并且保留2位小数,而且按距离远近进行排序
public List<HouseGeoDto> getHouseGeoDistance( String currentLongitude, String currentLatitude) {
List<HouseGeoDto> houseGeoList = infoHouseMapper.getHouseGeoList();
if (CollectionUtil.isNotEmpty(houseGeoList)){
for (HouseGeoDto dto : houseGeoList) {
double distance = getDistance(currentLongitude, currentLatitude, dto.getLongitude(), dto.getLatitude());
dto.setGeoDistance(distance);
}
}
//匿名比较器排序
// List<HouseGeoDto> collect = houseGeoList.stream().sorted(Comparator.comparing(HouseGeoDto::getGeoDistance,Comparator.nullsFirst(String::compareTo))).collect(Collectors.toList());
//匿名比较器排序
/* Collections.sort(houseGeoList, new Comparator<HouseGeoDto>() {
@Override
public int compare(HouseGeoDto o1, HouseGeoDto

本文介绍如何利用Redis的GEO功能精确计算两个地理坐标的距离,并且结果保留2位小数,同时展示如何按照距离远近进行排序。
最低0.47元/天 解锁文章
467

被折叠的 条评论
为什么被折叠?



