I developed an app that shows the weather conditions during the day. After creating my own Api key on https://openweathermap.org/api, I added the daily and 8-hour weather forecast service to my project. When requesting these services,
it asks me for Api key,
buildTypes {
release {
minifyEnabled false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
buildTypes.each {
it.buildConfigField 'String', 'API_KEY', '"0"'
it.resValue 'string', 'API_KEY', '"0"'
}
}
}
override fun getOneDayWeather(lat: Double, lon: Double): Single<WeatherOneDayResponse> {
return weatherApiService.getOneDayWeather(lat, lon, BuildConfig.API_KEY)
}
override fun getEightHourWeather(
lat: Double,
lon: Double
): Single<WeatherEightHourResponse> {
return weatherApiService.getEightHourWeather(lat, lon, BuildConfig.API_KEY)
}
latitude and longitude,
(WeatherFragment)
override fun onLocationChanged(location: Location) {
val geoCoder = Geocoder(requireContext(), Locale.getDefault())
val address = geoCoder.getFromLocation(location.latitude, location.longitude, 1)
val cityName = address?.get(0)?.adminArea
binding.tvCity.text = cityName
with(viewModel) {
getWeatherOneDay(location.latitude, location.longitude)
getEightHourWeather(location.latitude, location.longitude)
}
}
we asked the user for permission for the location and sent this information. In this way, I can show the user both the daily average and the weather conditions for certain hours during the day.