Kotlin Android Google Map Current LocationTo 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 MapThere 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. activity_maps.xmlAdd the following code in activity_maps.xml layout file. strings.xmlbuild.gradleAdd the Google Map Service and Google Location Service dependencies in build.gradle file. google_maps_api.xmlPlace the Google Map API key in res/values/google_map_api.xml file. MapsActivity.ktAdd the following code in MapsActivity.kt class file. AndroidManifest.xmlOutput: Note: Check it on the real Android device for the best result of output.![]()
Next Topic#
|