From 41452ccd3d31af83f15c27211f7269487b28568a Mon Sep 17 00:00:00 2001 From: androidlover5842 Date: Sat, 31 Jan 2026 11:01:40 +0530 Subject: [PATCH] Prefer district for pin geocode city --- .../component/GoogleGeocodingClient.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/android/trisolarisserver/component/GoogleGeocodingClient.kt b/src/main/kotlin/com/android/trisolarisserver/component/GoogleGeocodingClient.kt index f983649..34805d5 100644 --- a/src/main/kotlin/com/android/trisolarisserver/component/GoogleGeocodingClient.kt +++ b/src/main/kotlin/com/android/trisolarisserver/component/GoogleGeocodingClient.kt @@ -46,6 +46,7 @@ class GoogleGeocodingClient( if (!components.isArray) return null var city: String? = null + var admin2: String? = null var state: String? = null for (comp in components) { val types = comp.path("types").mapNotNull { it.asText(null) }.toSet() @@ -57,13 +58,12 @@ class GoogleGeocodingClient( "sublocality" in types -> if (city == null) { city = comp.path("long_name").asText(null) } - "administrative_area_level_2" in types -> if (city == null) { - city = comp.path("long_name").asText(null) - } + "administrative_area_level_2" in types -> admin2 = comp.path("long_name").asText(null) ?: admin2 "administrative_area_level_1" in types -> state = comp.path("long_name").asText(null) ?: state } } - if (city.isNullOrBlank() && state.isNullOrBlank()) return null - return listOfNotNull(city?.trim()?.ifBlank { null }, state?.trim()?.ifBlank { null }).joinToString(", ") + val preferredCity = admin2?.trim()?.ifBlank { null } ?: city?.trim()?.ifBlank { null } + if (preferredCity == null && state.isNullOrBlank()) return null + return listOfNotNull(preferredCity, state?.trim()?.ifBlank { null }).joinToString(", ") } }