Tuesday, April 19, 2016

Google Map API V2 Part-I (Prepare yourself to do fun with Google Map)

" Jai Saraswati Maa" 
Hi ... Dear All ..Today I am uploading a superb example Part I of my Google Map Series.
In this examples we are using Google Map API V2 latest one API for Google Map.
This example is just to setup your emulator to do fun with Google Map.
I am using Android Studio 1.5.1
Minimun SDK API 19
Target SDK API 23
*** Make sure Google Play Services is installed or not. (if not please install first)
*** add permission in manifest file like 
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
*** Add meta data tag within application tag like 
<meta-data    android:name="com.google.android.geo.API_KEY"

    android:value="@string/google_maps_key" />

**here Google Map API key is very important so i have added at the starting  of this 
    example how to get this Key.  Read Carefully  
Okkkkkkk... lets start

Create a new project with Google Map Activity 
It will generate one important file google_maps_api.xml file under Values folder.

***A .... How get Google API 
1. open Google Console API  use https://console.developers.google.com
2.   Click on Google Maps Android API in Google Maps APIs 
3. Enable this after Enabled it shows Disable option 
4. Go on Create a New Project Name your Project and click OK 
5. Now Create Credentials for API key 
6. Select Android Key   
7. Name your key and add package name and SHA1 fingerprint (Which you get from 
     google_maps_api.xml) like my is AA:A2:E3:05:65:2A:89:1E:83:81:8F:78:A0:89:73:1B 
     you should put yours  and insert your package name   and click on create copy 
     the key and put it in the google_maps_api.xml at the place of your key.
******* you should logged in to do all above steps.
A. Output will be like 
           
                  

B. Layout xml file is  activity_maps.xml is as 

<LinearLayout 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:layout_width="match_parent"

    android:layout_height="match_parent"

    android:orientation="vertical"

    tools:context="com.exam.ravi.googlemapex1.MapsActivity" >
    <fragment        android:id="@+id/map"

        android:name="com.google.android.gms.maps.SupportMapFragment"

        android:layout_width="match_parent"

        android:layout_height="match_parent"></fragment>
    </LinearLayout>

C. Java file is 

package com.exam.ravi.googlemapex1;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

public class MapsActivity extends AppCompatActivity

{

   private GoogleMap mMap;

   @Override   protected void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_maps);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
    .findFragmentById(R.id.map);
    }
}

No comments:

Post a Comment