Попробуйте добавить функцию в свой параметр типа функции. Как,
Класс обработчика прогноза погоды:
open fun getForecast(lat: Double, lng: Double, weatherKey: String, callback: ((result: ThreeHourForecast?) -> Unit)){
val helper = OpenWeatherMapHelper(weatherKey)
helper.setUnits(Units.METRIC)
helper.setLang(Lang.ENGLISH)
helper.getThreeHourForecastByGeoCoordinates(lat, lng, object : ThreeHourForecastCallback {
override fun onSuccess(threeHourForecast: ThreeHourForecast) {//send this "threeHourForecast" object back to the place from which "getForecast()" method is called.
callback(threeHourForecast)
}
override fun onFailure(throwable: Throwable) {
callback(null)
}
})
}
Класс активности карт:
override fun onMapReady(map: GoogleMap?) {
googleMap = map!!
val weatherHandler = WeatherForecastHandler()
weatherHandler.getForecast(startPoint.latitude, startPoint.longitude, getString(R.string.key) { result: ThreeHourForecast? ->
// You can now receive value of 'threeHourForecast'
}
//I need object here.
}