Google Maps Integration in Android Application Studio Example

How to show Google Map inside android app including location pin point tag to show your office college location.

Google Maps is word’s largest online maps college available on internet managed and served by Google itself. It is used by millions of peoples around the earth to find any place any where at any time with just few clicks. It also contain the most important information about the places like street name, city name, country name and popular place there. People can also add their home, office, buildings, schools, society in it by submitting their request to Google maps authentication. So in this tutorial we are going to add google map inside our android application with a certain type of pin point location tag method. So here is the complete step by step tutorial for Google Maps Integration in Android Application Studio Example.

android-project-download-code-button

Things required before getting started in this project :

  1. Internet connection .
  2. Longitude & Latitude of your location.
  3. A Gmail ID – To create Google Maps API key .
  4. Android studio latest updated version .
  5. Just read the rest of tutorial .

 Getting stated with Google Maps Integration in Android Application Studio Example step by step guide .

1. Start a new project in Android Studio .

2. Select minimum SDK .

3. Select Google Maps Activity .

5. Click on finish button .

6. After done loading your project click on google_maps_api.xml (debug) file .

7. Next step is to open your web browser and log in ti Gmail with your Google Gmail account .

8. Select and copy the whole line starts from ” https://console.developers.google.com/flows/enableapi? “ till the end like i did in below screenshot .

9. Paste the whole copied line into your web browser in which you have already logged in with your Gmail account .

10. Now Google APIs application registration page will be open on your screen so click on Continue button.

11. Click on Create API key button .

12. Here you go now your Google Maps authentication api key will be successfully create and shows on your screen, Copy the key .

13. Paste the copied api key into your google_maps_api.xml ( debug ) file .

Here you go guys now all the api related chapter is finish next step is to start coding.

Add the INTERNET, ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION permission in your AndroidManifest.xml file.

 <uses-permission android:name="android.permission.INTERNET" />

 <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

 <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Code for MainActivity.java file.

package com.android_examples.googlemaps_android_examplescom;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
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 com.google.android.gms.maps.model.MarkerOptions;


public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.fragmentMap);
        mapFragment.getMapAsync(this);
    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */

    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Copy your latitude & longitude here .
        LatLng ECBcollege = new LatLng(28.0600392, 73.2927772);

        mMap.addMarker(new MarkerOptions().position(ECBcollege).title("Engineering College Bikaner"));

        mMap.moveCamera(CameraUpdateFactory.newLatLng(ECBcollege));
    }
}

Code for activity_main.xml layout file.

<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragmentMap"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.android_examples.googlemaps_android_examplescom.MapsActivity" />

Code for AndroidManifest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android_examples.googlemaps_android_examplescom">

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->

    <uses-permission android:name="android.permission.INTERNET" />

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Screenshot :

Google Maps Integration in Android Application Studio Example

Click here to download Google Maps Integration in Android Application Studio Example project with source code.

2 Comments

  1. Very Nice Sir Thank You.

Leave a Reply

Your email address will not be published. Required fields are marked *