Kotlin Android Google Map Current Location
To implement the Google Map in an Android application, we need to generate the Google Map API key. The process of creating the Google Map API key is described in Google Map Fixed Location tutorial.
In the previous tutorial of Kotlin Android Google Map Fixed Location, we have displayed the fixed Google location.
Now in this tutorial, we will display and place the marker at user's current location. To view the user's current location, we need to implement some Google Map interfaces and call there callbacks methods.
Google Map API Interface
The isLocationEnabled property of GoogleMap is used to enable location layer, which allows the device to interact with the current location.
The tutorial using Java to display Google Map user's current location is described at Android Google Map Displaying Current Location.
Types of Google Map
There are four different types of Google map are available in map API. Each of them has different view of the map. These types are Normal, Hybrid, Satellite and Terrain.
Using Kotlin syntax, we will use the above Google map types as:
The detail about these map types are explain here.
Add the following code in activity_maps.xml layout file.
Add the Google Map Service and Google Location Service dependencies in build.gradle file.
Place the Google Map API key in res/values/google_map_api.xml file.
Add the following code in MapsActivity.kt class file.
Note: Check it on the real Android device for the best result of output.