Javatpoint Logo
Javatpoint Logo

Kotlin Android Google Map Fixed Location

Google Map displays the current location, navigate location direction, search location etc. To place the Google Map in an application, we need to create the Google Map API key and integrate it in our application.

The Google Map tutorial using Java code is implemented at Android Google Map.

In this tutorial, we will integrate the Google Maps in our Android application. To place the Google Map in application, selects the activity type as Google Maps Activity. By default this activity generates the required configuration and setting which are required for Google map.

Kotlin Android Google Map Fixed Location

To implement the Google Map, we need to generate the Google Map API key and integrate it into our application.

Copy the URL from res/values/google_map_api.xml file and paste it at the browser or we can directly visit at Console Google Developer to generates the Google Map API key.

Kotlin Android Google Map Fixed Location Kotlin Android Google Map Fixed Location

Click on Create API key to generate API key.

Kotlin Android Google Map Fixed Location

After clicking on Create API key, it will generate our API key displaying the following screen.

Kotlin Android Google Map Fixed Location

Paste the generated API key in our res/values/google_map_api.xml file.

Kotlin Android Google Map Fixed Location

activity_maps.xml

Add the following code in activity_maps.xml layout file.

build.gradle

Add the Google Map Service and Google Location Service dependencies in build.gradle file.

strings.xml

google_map_api.xml

Place the Google Map API key in res/values/google_map_api.xml file.

MapsActivity.kt

To get the GoogleMap object in our MapsActivity.kt class, we need to implement the OnMapReadyCallback interface and override the onMapReady() callback method. To display the fix location on map, place the latitude and longitude point in the LatLng(latitude, longitude).

GoogleMap.addMarker() points the location of given location.

AndroidManifest.xml

Add the in AndroidManifest.xml file.

Output:

Kotlin Android Google Map Fixed Location

MapsActivity.kt

The application built on version Marshmallow facilitates run time user permission. In this class, we create the above example by providing the run time permission to access the device fine location ACCESS_FINE_LOCATION.

Output:

Kotlin Android Google Map Fixed Location Kotlin Android Google Map Fixed Location
Next Topic#




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA