0

I want to display Google map in android application. I have done following steps.

  1. Created a new android application project with the package name com.gaurav.googlemap
  2. Downloaded Google Play Services SDK from SDK Manager
  3. Imported 'google-play-services_lib' into current workspace
  4. Linked 'google-play-services_lib' to my current project

    (Project properties -> Android -> Add(Into Library Section) -> Selected 'google-play-services_lib'-> Apply -> Ok

  5. Registered SHA-1 fingerprint with following command

    keytool -list -v -keystore "%USERPROFILE%.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

  6. Generated Android API key from Google API console

  7. Modified AndroidManifest.xml as below

    <?xml version="1.0" encoding="utf-8"?>
    

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="17" />
    
    <permission 
        android:name="com.gaurav.googlemap.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"></permission>
    <uses-permission 
        android:name="com.gaurav.googlemap.permission.MAPS_RECEIVE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    
    <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" >
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyC3hd_PcjjfraFGfnx3UVi0FLO5AwgxFT8" />
        <activity
            android:name=".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>
    </application>
    

  8. Modified activity_main.xml as below

    <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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.gaurav.googlemap.MainActivity" >
    
    
    <fragment 
        android:id="@+id/map"
        class="com.google.android.gms.maps.MapFragment"
        android:layout_height="match_parent"
        android:layout_width="match_parent"/>
    

  9. Modified MainActivity.java as below

    package com.gaurav.googlemap;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;
    import android.view.MenuItem;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentActivity;

    public class MainActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
    

    }

  10. And finally I ran project into Android emulator

But there is a exception in LogCat as below

02-14 16:41:46.947: E/AndroidRuntime(1260): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gaurav.googlemap/com.gaurav.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class fragment

I have read many answers on similar questions, but I didn't get this problem fix. I am having operating system Windows 8.1 (32-bit)

I have heard there is a different way to setup emulator to display Google map. Is this related to my problem?

Please help me to fix this problem. Thanks.

5
  • Post the code of your activity Commented Feb 14, 2015 at 18:14
  • Has this class been added/imported into your project? Some of the links online say you need to also add google play services. Commented Feb 14, 2015 at 18:23
  • Add this in AndroidManifest.xml <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> Commented Feb 14, 2015 at 18:32
  • Does it require Google APIs SDK? Commented Feb 14, 2015 at 19:01
  • Added it in answer, accept it as answered as it worked for you. Commented Feb 14, 2015 at 19:16

1 Answer 1

3

Add this in AndroidManifest.xml

<meta-data android:name="com.google.android.gms.version" 
android:value="@integer/google_play_services_version" />
Sign up to request clarification or add additional context in comments.

1 Comment

please share the reason as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.