From 966b53963f2567c3602ee18436c5d6fe72589682 Mon Sep 17 00:00:00 2001 From: Jude Date: Wed, 25 Sep 2024 20:40:17 +0900 Subject: [PATCH] =?UTF-8?q?=E3=85=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../photobook/application/NaverGcService.kt | 20 +++++++++++++++---- .../application/dto/NaverGcResponse.kt | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/ggsdh/backend/photobook/application/NaverGcService.kt b/src/main/kotlin/com/ggsdh/backend/photobook/application/NaverGcService.kt index 784dfee..6ec2f15 100644 --- a/src/main/kotlin/com/ggsdh/backend/photobook/application/NaverGcService.kt +++ b/src/main/kotlin/com/ggsdh/backend/photobook/application/NaverGcService.kt @@ -27,7 +27,7 @@ class NaverGcService( return asyncHttpClient .prepareGet( - "https://naveropenapi.apigw.ntruss.com/map-reversegeocode/v2/gc?coords=${input.lon},${input.lat}&output=json&orders=roadaddr", + "https://naveropenapi.apigw.ntruss.com/map-reversegeocode/v2/gc?coords=${input.lon},${input.lat}&output=json&orders=legalcode,roadaddr", ).setHeader("X-NCP-APIGW-API-KEY", clientSecret) .setHeader("X-NCP-APIGW-API-KEY-ID", clientId) .execute() @@ -41,9 +41,21 @@ class NaverGcService( return@thenApply null } + if(response.results.size == 1) { + val city = + response.results[0] + .region.area1.name + + val roadName = + response.results[0] + .region.area4.name + + return@thenApply Location(input.lat, input.lon, "$roadName 근처 어딘가", city) + } + val buildingName = - response.results[0] - .land.addition0.value + response.results[1] + .land?.addition0?.value ?: "" val city = response.results[0] @@ -52,7 +64,7 @@ class NaverGcService( if (buildingName == "") { val roadName = response.results[0] - .land.name + .land?.name return@thenApply Location(input.lat, input.lon, "$roadName 근처 어딘가", city) } else { return@thenApply Location(input.lat, input.lon, buildingName, city) diff --git a/src/main/kotlin/com/ggsdh/backend/photobook/application/dto/NaverGcResponse.kt b/src/main/kotlin/com/ggsdh/backend/photobook/application/dto/NaverGcResponse.kt index b3a99e3..1dda25a 100644 --- a/src/main/kotlin/com/ggsdh/backend/photobook/application/dto/NaverGcResponse.kt +++ b/src/main/kotlin/com/ggsdh/backend/photobook/application/dto/NaverGcResponse.kt @@ -15,7 +15,7 @@ data class Result( val name: String, val code: Code, val region: Region, - val land: Land, + val land: Land?, ) data class Code(