We could successfully run the app, and now it is time to delve deeper into the code and understand how it works.
Let's start with the MapsActivity.kt
Kotlin class file.
The MapActivity
class extends the AppCompatActivity
class and also implements the OnMapReadCallback
interface. We have a couple of variables, GoogleMap
, mMap
and btn
button initialized.
Overriding the onCreate
method, the app is set to load the content from the XML file, activity_maps.xml
, as and when the app is launched.
The resources for the mapFragment
and btn
are set from the resources file:
class MapsActivity : AppCompatActivity(), OnMapReadyCallback { private lateinit var mMap: GoogleMap override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_maps) // Obtain the SupportMapFragment and get notified when the map is ready to be used. val mapFragment = supportFragmentManager .findFragmentById(R.id.map) as SupportMapFragment ...