Maps are of great use and it increases the productivity of an app. Google Maps API allows Android developers to integrate Google Maps in their app. Below is the step-by-step process to integrate Google Maps into Android applications:
- Goto https://developers.google.com/maps/documentation/android-sdk/get-api-key and click on "GET STARTED" button as shown in the figure:

- Now select the Map checkbox and click on the Continue button as shown below:

- Select a project in which you want to enable Google Map API, and click on Next. A new key will be generated for the chosen project.

- Skip the Billing Process
- For integrating Google Map API, your machine's SHA1 certificate is needed. So to find SHA1 certificate, follow below steps:
- Open Command Prompt and go to your Java bin Folder
cd C:\Program Files\Java\jdk1.8.0_91\bin
- Give the following CMD command for getting Certificate Footprints:
keytool -list -v -keystore "%USERPROFILE%\.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android
- Go to https://accounts.google.com/v3/signin/identifier?continue=https%3A%2F%2Fconsole.cloud.google.com%2Fapis%2Fcredentials&followup=https%3A%2F%2Fconsole.cloud.google.com%2Fapis%2Fcredentials&ifkv=AdBytiMAoknixS1AYi5QAHFJ68Hz1jVVHrl5gYrWayMf-v1sZ0LK3hmQUcxb1ONzf09_PM2It5s38Q&osid=1&passive=1209600&service=cloudconsole&flowName=WebLiteSignIn&flowEntry=ServiceLogin&dsh=S-1389637297%3A1752216380674114
- In the API keys section, click on Pencil button made on the right of API key that you want to select, for attaching your app with.

- In Application Restrictions, select Android apps

- Click on Add package name and fingerprint
- Enter your app's package name and the fingerprint which was found in above steps and click Save button.

- Insert the following in Project ->app ->src ->build.gradle ->dependencies
compile 'com.google.android.gms:play-services:11.6.0'
- Add the following declaration within the element of AndroidManifest.xml
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="ENTER API_KEY GENERATED BY YOU IN ABOVE STEPS" />
- Add the following permissions in Manifest.xml
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.INTERNET" />
<uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE" />
- Specify following specifications in Manifest.xml
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
- Add the following fragment code in ActivityMain.xml for adding Google map to your activity.
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
- Add the following code in MainActivity.java
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import androidx.appcompat.app.AppCompatActivity;
public class MapsMarkerActivity extends AppCompatActivity implements OnMapReadyCallback {
// onCreate method is called when the activity is first created
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Retrieve the content view that renders the map.
setContentView(R.layout.ActivityMain);
// Get the SupportMapFragment and request notification
// when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
// This method is called when the map is ready to be used.
@Override
public void onMapReady(GoogleMap googleMap) {
// Add a marker in Sydney, Australia,
// and move the map's camera to the same location.
LatLng myPos = new LatLng(Location.getLatitude(), Location.getLongitude());
googleMap.moveCamera(CameraUpdateFactory.newLatLng(myPos));
}
}
- Run the code.
