Prefer district for pin geocode city
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 33s
This commit is contained in:
@@ -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(", ")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user