-
-
Save Arunshaik2001/1916bbb9a884e6ef958896e7234b3e56 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this) | |
fun createLocationRequest(context: Context,fusedLocationClient: FusedLocationProviderClient) { | |
val locationRequest = LocationRequest.create().apply { | |
interval = 1000 | |
fastestInterval = 1000 | |
priority = LocationRequest.PRIORITY_BALANCED_POWER_ACCURACY | |
} | |
if (ActivityCompat.checkSelfPermission( | |
context, | |
Manifest.permission.ACCESS_FINE_LOCATION | |
) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission( | |
context, | |
Manifest.permission.ACCESS_COARSE_LOCATION | |
) != PackageManager.PERMISSION_GRANTED | |
) { | |
return | |
} | |
fusedLocationClient.requestLocationUpdates(locationRequest,object : LocationCallback() { | |
override fun onLocationResult(p0: LocationResult) { | |
for (location in p0.locations){ | |
CoroutineScope(Dispatchers.IO).launch { | |
val weatherDTO = WeatherApi | |
.apiInstance | |
.getWeatherDetails(location.latitude, | |
location.longitude, | |
context.resources.getString(com.example.wear2.R.string.open_weather_api_key)) | |
dataLoaded.value = true; | |
data.value = AppCardData(name = weatherDTO.name, | |
time = "${(weatherDTO.main.temp - 273).roundToInt()}°C", | |
weatherDescription = weatherDTO.weather[0].description, | |
temp = (weatherDTO.main.temp - 273).roundToInt().toDouble() | |
) | |
} | |
} | |
} | |
}, Looper.getMainLooper()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment