Open top menu


In this tutorial we will implement Google Map with Google Map API in android. so,explain Step by Step.

Step .1:- Frist ,you can register you android project on  Google Developer Console get the api key.the api key get via SHA-1 fingerprint.

Step 2:-Open Google Developer Console link.

Step 3:- Add Map Key in Manifest Class.
..................................................................................................................................................................

<meta-data  
android:name="com.google.android.geo.API_KEY"  
android:value="Paste_your_key"/>

.................................................................................................................................................................


Step 3:-  Google map need some Permission so you have to add in manifest ,

AndroidManifast.xml
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

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

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

<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="myapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>  
      
<uses-feature            
android:glEsVersion="0x00020000"            
android:required="true"/>

        
<meta-data            
android:name="com.google.android.geo.API_KEY"            
android:value="Api_key"/>   
</application>
</manifest>


..................................................................................................................................................................


Step 4:- Then google maps are implement MapFragment which is subclass of  Fragment. open your activity_main and add this fragment in Layout.

activity_main.xml
...................................................................................................................................................................

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    
android:layout_width="match_parent"    
android:layout_height="match_parent"    
android:background="@drawable/register_cover"    
android:orientation="vertical"    
android:padding="10dp">

    
<fragment        
android:name="com.google.android.gms.maps.MapFragment"        
android:id="@+id/map"        
android:layout_width="match_parent"        
android:layout_height="match_parent"/>

</LinearLayout>
...................................................................................................................................................................



Step 5:-  then, implement some code in MainActivity.java class.

...................................................................................................................................................................
package com.example.sarvesh.testproject;

import android.app.ActionBar;
import android.app.Activity;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.SparseBooleanArray;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

import java.util.ArrayList;

public class MainActivity extends Activity {

    // Google Map    private GoogleMap googleMap;
    double latitude = 20.5937;
    double longitude =78.9629;


    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try {
            // Loading map            initilizeMap();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    /**     * function to load map. If map is not created it will create it for you     */   
 private void initilizeMap() {
        
if (googleMap == null) {
          
  googleMap = ((MapFragment) getFragmentManager().findFragmentById( R.id.map)).getMap();
  MarkerOptions marker = new MarkerOptions().position(new LatLng(latitude, longitude)).title("Androidbeginnerpoint");
  googleMap.addMarker(marker);

            
// check if map is created successfully or not            
if (googleMap == null) {
   Toast.makeText(getApplicationContext(),"Sorry! unable to create maps", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }
    @Override    protected void onResume() {
        super.onResume();
        initilizeMap();
    }
}

.................................................................................................................................................................


 try this tutorial....







Tagged

0 comments