Resolve pin via data.gov.in with fallbacks
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s

This commit is contained in:
androidlover5842
2026-01-31 11:48:02 +05:30
parent 796d9f35b0
commit e9e39e645c
6 changed files with 189 additions and 27 deletions

View File

@@ -68,15 +68,6 @@ 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
@@ -101,18 +92,6 @@ 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(
@@ -120,3 +99,10 @@ data class GeocodeResult(
val rawResponse: String?,
val status: String?
)
data class PincodeLookupResult(
val resolvedCityState: String?,
val rawResponse: String?,
val status: String?,
val source: String
)