Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

321
Views
Android getMapAsync después de Kotlin Coroutine

Tengo una aplicación que se conecta a una API usando una actualización y muestra los datos en una vista de reciclador, ahora he agregado otro fragmento que muestra estos datos en un fragmento de mapa de Google.

El fragmento de mapa está bien cuando navego hacia él después del fragmento de vista del reciclador; sin embargo, si inicio la aplicación y navego directamente hasta el fragmento de mapa, ninguno de los datos está allí y el tamaño de los datos es 0.

Aquí está el fragmento del fragmento del mapa:

 val livePointViewModel: ChargePointViewModel by activityViewModels() livePointViewModel.getChargePointQuery() // bind viewmodel to view binding.livePointsViewModel = livePointViewModel binding.lifecycleOwner = this livePointViewModel.status.observe(viewLifecycleOwner, Observer { when (it) { ChargeQueryAPIStatus.LOADING -> Timber.d("0 - map points query loading") ChargeQueryAPIStatus.DONE -> { Timber.d("0 - map points query complete") livePointViewModel.listOfChargePoints.observe(viewLifecycleOwner, Observer { it?.let { Timber.d("1 - map points observed") when{ it.isEmpty() -> Timber.d("2.1- map points live charge point size:${it.size}") it.isNotEmpty() -> generateMap() } } }) } } })

Aquí está mi función .getChargePointQuery:

 fun getChargePointQuery() { viewModelScope.launch { _status.value = ChargeQueryAPIStatus.LOADING try { _response.value = "Loading" val chargeQuery: ChargeQuery? // check if using live location or using static postcode if (useLocation.value == true) { chargeQuery = ChargeApi.retrofitService.getChargeQueryObjectLocation( myLatitude.value.toString(), myLongitude.value.toString(), distance.value.toString(), limit.value.toString() ) } else { // using postcode chargeQuery = ChargeApi.retrofitService.getChargeQueryObjectPostcode( postcode.value.toString(), distance.value.toString(), limit.value.toString() ) } _listOfChargePoints.value = convertChargePoints(chargeQuery.chargeDevices) _status.value = ChargeQueryAPIStatus.DONE } } catch (e: Exception) { _status.value = ChargeQueryAPIStatus.ERROR _response.value = "Failure: ${e.message}" } } }

Mi fragmento de recyclerview envía la lista de datos al adaptador y luego solo hace que la vista sea visible cuando el estado cambia a HECHO; sin embargo, en el fragmento de mapa, intenté hacer lo mismo, pero cuando estaba en la rama HECHO, mi lista de datos todavía parece estará vacío y no se generará el mapa.

Aquí está todo mi proyecto si eso ayuda: https://github.com/Kovah101/ChargeMyCar

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Pude resolver esto yo mismo. Al comparar mi lista en vivo con mis fragmentos de mapas en vivo, eran casi idénticos, excepto por la forma en que navegabas hacia ellos. Para la lista en vivo, establecería la variable useLocation.value = true , sin embargo, para el fragmento de mapa en vivo, la variable no se inicializó. Ahora configuro el valor predeterminado de useLocation.value = true antes de que tenga lugar cualquier navegación.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!