Skip to main content

Android - Google MAP V2 PART 1




Download and configure Google Play Services Library in Eclipse

Google Map for Android is now integrated with Google Play Services. So we need to set up Google Play Service Library for developing Google Map application in Android.


Get the API key for Google Maps v2:
Linux : 


For any other OS use this : 

 keytool -list -v -alias androiddebugkey \  
 -keystore <path_to_debug_keystore>debug.keystore \  
 -storepass android -keypass android   


Register with the Google APIs Console :  Google APIs Console 

Select here the Services entry:

Activate the Google Maps Android API v2.



Register your application via its package in this console together with the SHA-1 fingerprint of your signature key.
Click on Create new Android Key..

Add you SHA-1 and your package name in to box like example given in alert box.

Support library : Android support library (android-support-v4.jar ) is added to this project by Eclipse IDE to the directory libs.

Now,

 Add Play Services Library in project :  
 Eclipse > import > Android > Existing Android code in to workspace  
 Browse you SDK path like ~/android-sdk-linux/extras/google/google_play_services  
 import that project in to workspace  


EDIT : 28/03/14 : if you have google play services rev 13 and more then use below lines in android manifest file.

 <application  
 ...  
  <meta-data  
   android:name="com.google.android.gms.version"  
   android:value="@integer/google_play_services_version" />  
 </application>  



Create New Android Project and flow below step: 

Add library project in to new Project : Project > properties > android > in library section > Add > google_play_services

now in your manifest file :
 <?xml version="1.0" encoding="utf-8"?>  
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"  
   package="com.djandroid.mapsv2"  
   android:versionCode="1"  
   android:versionName="1.0" >  
   <uses-sdk  
     android:minSdkVersion="8"  
     android:targetSdkVersion="16" />  
   <uses-permission android:name="android.permission.INTERNET" />  
   <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />  
   <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />  
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />  
   <uses-permission android:name="com.djandroid.mapsv2.permission.MAPS_RECEIVE" />  
   <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />  
   <uses-feature  
     android:glEsVersion="0x00020000"  
     android:required="true" />  
   <application  
     android:allowBackup="true"  
     android:icon="@drawable/ic_launcher"  
     android:label="@string/app_name"  
     android:theme="@style/AppTheme" >  
     <activity  
       android:name="com.djandroid.mapsv2.MainActivity"  
       android:label="@string/app_name" >  
       <intent-filter>  
         <action android:name="android.intent.action.MAIN" />  
         <category android:name="android.intent.category.LAUNCHER" />  
       </intent-filter>  
     </activity>  
     <meta-data  
       android:name="com.google.android.maps.v2.API_KEY"  
       android:value="API_KEY" />  
     <uses-library  
       android:name="com.google.android.maps"  
       android:required="true" />  
   </application>  
 </manifest>  

you layout file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:tools="http://schemas.android.com/tools"  
   android:layout_width="match_parent"  
   android:layout_height="match_parent"  
   tools:context=".MainActivity" >  
   <fragment  
     android:id="@+id/fragment1"  
     android:layout_width="match_parent"  
     android:layout_height="match_parent"  
     class="com.google.android.gms.maps.SupportMapFragment" />  
 </RelativeLayout>  

Main Activity :
 package com.djandroid.mapsv2;  
 import android.app.Activity;  
 import android.os.Bundle;  
 import android.support.v4.app.FragmentActivity;  
 public class MainActivity extends FragmentActivity {  
      @Override  
      protected void onCreate(Bundle arg0) {  
           // TODO Auto-generated method stub  
           super.onCreate(arg0);  
           setContentView(R.layout.activity_main);  
      }  
 }  

 You have to test the application on a real device as the emulator is not supported.

Download Full Code of PART-1,2,3,4

Comments

  1. This works! I just tested this on a phone running Gingerbread (2.3.5) and it worked perfectly! Thank you very, very much!

    ReplyDelete
  2. Thank you. Your posts helped me a lot!

    ReplyDelete
  3. how can i run This Application in Android Emulator..

    ReplyDelete
    Replies
    1. I was written at end of blog.. "Google map v2 is not run in emularot"

      If you want to run then install "google play services" & "GSM services in emularot then its run in emulator.

      I dont thik we can do that.. So, is not possibke to run Google map v2 in emulator...

      Delete
  4. hi
    am getting white screen with android 4.0.4 device

    ReplyDelete
    Replies
    1. your code working in any other device? have you checked this?? if it work in any other android device with < 4.0 OS then replay me here with your code.

      or if it not work in every device then check your code once again... do all step again which i have explain in above artical.

      Delete
  5. Hi dhaval,

    I have created a key, installed google play services and using tat jar file in my app but the moment when i click maps it crashes.
    I am using 4.1.2 nexus.

    ReplyDelete
    Replies
    1. please check logs... and tell me what type of exception you get??

      Delete
  6. java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
    but the sample app runs properly in device

    ReplyDelete
    Replies
    1. you have't add google Play library in your Project check below links.

      http://stackoverflow.com/a/16305851/1168654

      http://stackoverflow.com/a/14639026/1168654

      http://stackoverflow.com/a/15894284/1168654

      Delete
  7. I can't copy your code. Can't get it into the clipboard. Do you have a downloadable working project?

    ReplyDelete
    Replies
    1. code is here: https://github.com/dhaval0122/DJ-Android-

      Delete

Post a Comment

Popular posts from this blog

Why Domain-Specific AI Agents Beat One Big Agent

Everyone is building agents right now. Real estate firms. Independent insurance brokers. Fortune 500 companies with budgets big enough to hire an army of consultants. Ask around and you'll hear the same story everywhere: "we're building our own agent." And yet almost nobody is asking the obvious question: why does the default approach keep failing? One large, general-purpose agent gets wired up to every tool the business owns. It impresses in the demo. Then it quietly stalls before production. There's a gap between what businesses want and what they're actually getting. They want AI woven into their data, their workflows, their day-to-day operations. What they get instead is one oversized agent trying to be a sales rep, a compliance officer, and a customer support line, all at once. That gap is an architecture problem, not a model problem. Key Takeaways The default "one big agent" pattern breaks down on context bloat, cost, fragility, and portability...

Android show Data from Sqlite DB into Grid View

Shaadi.com Matrimonials Shaadi.com Indian Matrimonials Your Main Activity class package com . Sqlite_grid_view ; import java . util . ArrayList ; import java . util . List ; import android . app . Activity ; import android . os . Bundle ; import android . util . Log ; import android . view . View ; import android . widget . AdapterView ; import android . widget . AdapterView . OnItemClickListener ; import android . widget . ArrayAdapter ; import android . widget . GridView ; import android . widget . TextView ; import android . widget . Toast ; public class AndroidSQLiteTutorialActivity extends Activity { private GridView gridView ; public static ArrayList < String > ArrayofName = new ArrayList < String >(); /** Called when the activity is first created. */ @ Override public void onCreate ( Bundle savedInstanceState ) { super . onCreate ( savedInstanceState ); setContentView ( R . l...

Stop Babysitting your AI Coding Agent Every Single Session

  Watched a video by DSquaredLabs on " No more re-explaining: Give your AI agent a memory graph " — here's what stuck with me and why I think this three-tool system is worth your attention If you work on a large codebase with AI coding tools, you already know the ritual. Open a new chat, paste your file structure, explain your stack, describe how the modules connect — and repeat the whole thing tomorrow. It is not a minor inconvenience. It is a compounding productivity tax that gets worse as your project grows. This article breaks down a three-tool system designed to fix exactly that. If you want the full walkthrough with a live demo on a real monorepo, the video at the bottom covers everything in depth — but the core concepts are worth understanding before you dive in. The Problem With How Most Developers Use AI Today Most AI-assisted coding workflows are missing three things that every good engineering team actually has: A map of the codebase A process for how w...