diff --git a/src/main/kotlin/com/android/trisolarisserver/component/GoogleGeocodingClient.kt b/src/main/kotlin/com/android/trisolarisserver/component/GoogleGeocodingClient.kt index eeefd7c..29de383 100644 --- a/src/main/kotlin/com/android/trisolarisserver/component/GoogleGeocodingClient.kt +++ b/src/main/kotlin/com/android/trisolarisserver/component/GoogleGeocodingClient.kt @@ -68,6 +68,15 @@ class GoogleGeocodingClient( val resultNode = results.firstOrNull { node -> node.path("types").any { it.asText(null) == "postal_code" } } ?: results.first() + val postcodeLocalities = resultNode.path("postcode_localities") + if (postcodeLocalities.isArray) { + val candidates = postcodeLocalities.mapNotNull { it.asText(null) } + val agra = candidates.firstOrNull { it.equals("Agra", ignoreCase = true) } + if (agra != null) { + val stateOnly = extractState(resultNode) + return listOfNotNull(agra, stateOnly).joinToString(", ") + } + } val components = resultNode.path("address_components") if (!components.isArray) return null @@ -92,6 +101,18 @@ class GoogleGeocodingClient( if (preferredCity == null && state.isNullOrBlank()) return null return listOfNotNull(preferredCity, state?.trim()?.ifBlank { null }).joinToString(", ") } + + private fun extractState(resultNode: com.fasterxml.jackson.databind.JsonNode): String? { + val components = resultNode.path("address_components") + if (!components.isArray) return null + for (comp in components) { + val types = comp.path("types").mapNotNull { it.asText(null) }.toSet() + if ("administrative_area_level_1" in types) { + return comp.path("long_name").asText(null) + } + } + return null + } } data class GeocodeResult(