I need some help on how can I separate each data values inside the API response -> name from mapbox API in
autocomplete`PlaceAutocompleteAddress(houseNumber=6b, street=Luthens Gränd, neighborhood=null, locality=null, postcode=118 66, place=Stockholm, district=null, region=Stockholm, country=Sweden, formattedAddress=Luthens Gränd 6b, 118 66 Stockholm, Sweden, countryIso1=se, countryIso2=SE-AB)`
I expect I can get it like field.
private fun getPlaceByCoordinates(id:String,point: Point){
//lifecycle response for autocomplete
lifecycleScope.launchWhenCreated {
val response = placeAutocomplete.suggestions(point)
if (response.isValue) {
val suggestions = requireNotNull(response.value)
if (suggestions.isNotEmpty()) {
val selectedSuggestion = suggestions.first()
val selectionResponse = placeAutocomplete.select(selectedSuggestion)
selectionResponse.onValue { result ->
val newToilet = Toilet(id,result.coordinate.longitude(),
result.coordinate.longitude(),
result.name,result.address.toString())
addData(newToilet)
Toast.makeText(context,"equivalent: $result",Toast.LENGTH_SHORT).show()
}.onError { e ->
Log.i("callApi", "An error occurred during selection", e)
}
}
} else {
Log.i("callApiError", "Place Autocomplete error", response.error)
}
}
}
This is my current code, I'm saving it on Firebase database.