Maps activity in android app

Hey Technoz, today we’ll see how to integrate Google maps in our android app. If you are using Android Studio, you can directly use ‘Google Maps Activity’ from file menu and it’ll generate a ready made MapsActivity. However, we’ll discuss whole tutorial Step by Step.

Integrate Map in android app

So, open Android Studio and start a new project using File->New->Google->Google Maps Activity. Let the gradle build finish and as a result, you’ll have one java file and two xml files. Here, the java file is as follows.

This file contains overridden function onMapReady which is responsible to add marker in the map. Here, we created the object of LatLng class-‘sydney’. ‘LatLng’ stand for Latitude and Longitude. The constructor takes parameters of latitude and longitude respectively and the marker is set according to the values. The addMarker() function adds the title and custom icon (optional). If it is not set, the api uses the default red mark icon.

The layout files will be create as follows.

Lets see google_maps_api.xml file in values directory as follows.

Copy and paste the above url in browser, The system will redirect you to the Google API’s page as shown below.

maps activity in android

Click Continue, and as a result, it will generate new api key for your app as shown below.

maps activity in android

Copy this key and paste it in above file as a string value.

Lastly, add following permissions in your AndroidManifest.xml files as follows. I have pasted Whole file for clarification.

So, launch the app on emulator or real device, Lets see the map on screen with a red marker on map in below image.

maps activity in android

Obviously, We need the device which have Google Play Services installed see a map. Otherwise, the api will tell the user to update it.

Download Source Code

If you have any problems implementing the above code, then feel free comment below. We’ll try our best to solve your query. Alternatively, You can download the source code from below link.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.