我如何在 kotlin 中从 fun onResult 获取数据到 fun onMapReady

How I get data from fun onResult to fun onMapReady in kotlin

我使用改装从 API 获取数据。我将在地图中显示数据。数据成功地从改造中获取,但我发现问题获取数据响应有趣的 onMapReady。我不知道是什么

class HomeMapsActivity : AppCompatActivity(), OnMapReadyCallback,
MapHomeContract.View {

private lateinit var mMap: GoogleMap
 lateinit var presenter: MapHomePresenter
 lateinit var prefsManager: PrefsManager

override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_home_maps)
    supportActionBar!!.title = "Posisi driver"
    supportActionBar!!.setDisplayHomeAsUpEnabled(true)

    // Obtain the SupportMapFragment and get notified when the map is ready to be used.
    val mapFragment = supportFragmentManager
        .findFragmentById(R.id.map) as SupportMapFragment
    mapFragment.getMapAsync(this)

    prefsManager = PrefsManager(this)
    presenter = MapHomePresenter(this)
    presenter.getAnak(prefsManager.prefsIdUser)

}

override fun onMapReady(googleMap: GoogleMap) {

    mMap = googleMap


    for (dataAnak in anak) {
        // Add a marker in Sydney and move the camera
        val sydney = LatLng(-34.0, 151.0)
        mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
    }
}


override fun onResult(dataAnakResponse: AnakResponse) {
    dataAnakResponse.anak
}

}

请帮忙

onMapReady() 在您最初启动地图 Activity 时被调用。你可以在onResult中设置地图数据。

override fun onResult(dataAnakResponse: AnakResponse) {
   val anak =  dataAnakResponse.anak

for (dataAnak in anak) {
        // Add a marker in Sydney and move the camera
        val sydney = LatLng(-34.0, 151.0)
        mMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
    }
}