I use retrofit for get data From API. i will displays data ini the maps. data was successfull get from retrofit, but i found problem get data response to fun onMapReady. i don't know to be it
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
}
}
please help
onMapReady() is called when you initially start the Map Activity. You can set the map data in 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))
}
}