From c765483a4a3fc4faf0c385e25c4234dd60ec9d1b Mon Sep 17 00:00:00 2001 From: wellbeing-dough Date: Wed, 24 Jan 2024 03:41:04 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EC=9C=84=EB=8F=84=20=EA=B2=BD?= =?UTF-8?q?=EB=8F=84=20=EA=B8=B0=EB=B0=98=20=EA=B1=B0=EB=A6=AC=20=EA=B3=84?= =?UTF-8?q?=EC=82=B0=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jurumarble/drink/service/DrinkService.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java b/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java index 232f146..0de88b9 100644 --- a/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java +++ b/src/main/java/co/kr/jurumarble/drink/service/DrinkService.java @@ -103,11 +103,27 @@ public Slice getMapInDrinks(Double startX, Double startY log.info("********************" + endY); log.info("*******************" + (endX - startX)); log.info("*******************" + (endY - startY)); + double distance = calculateDistanceInKm(startX, startY, endX, endY); + log.info("^^^^^^^^^^^^^^^^^^^^^^^^^^" + distance); PageRequest pageRequest = PageRequest.of(page, size); Slice drinkData = drinkRepository.findDrinksByCoordinate(pageRequest, startX, startY, endX, endY); return new SliceImpl<>(getGetMapInDrinksResponses(drinkData), drinkData.getPageable(), drinkData.hasNext()); } + public double calculateDistanceInKm(double startX, double startY, double endX, double endY) { + final int R = 6371; // 지구의 반지름 + + double latDistance = Math.toRadians(endX - startX); + double lonDistance = Math.toRadians(endY - startY); + + double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2) + + Math.cos(Math.toRadians(startX)) * Math.cos(Math.toRadians(endX)) + * Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2); + double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + + return R * c; + } + private List getGetMapInDrinksResponses(Slice drinkData) { return drinkData.stream() .map(MapInDrinkData::toMapInDrinksResponse)