Click here to Skip to main content
14,484,661 members
Rate this:
Please Sign up or sign in to vote.
Not able to use android google map v2 in android app please have look and let me know where i am doing wrong..

Following is the Code for my MainActivity.java

package com.example.googlemapv2;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

public class MainActivity extends Activity {

	// Google Map

	private GoogleMap googleMap;

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

		try {
			initializeMap();

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

	@SuppressLint("NewApi")
	private void initializeMap() {
		if (googleMap == null) {
			googleMap = ((MapFragment) getFragmentManager().findFragmentById(
					R.id.map)).getMap();

		}
		if (googleMap == null) {

			Toast.makeText(getApplicationContext(),
					"Sorry, Unable to Show Map", Toast.LENGTH_SHORT).show();
		}
	}

	@Override
	protected void onResume() {
		
		super.onResume();
		initializeMap();

	}

}

And AndroidManifest.xml:


<manifest xmlns:android="http://schemas.android.com/apk/res/android">
    package="com.example.googlemapv2"
    android:versionCode="1"
    android:versionName="1.0" &gt;



    <uses-sdk>
        android:minSdkVersion="8"
        android:targetSdkVersion="14" /&gt;

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

    &lt;!-- Required to show current location --&gt;

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

    &lt;!-- Required OpenGL ES 2.0. for Maps V2 --&gt;
    <uses-feature>
        android:glEsVersion="0x00020000"
        android:required="true" /&gt;

    <application>
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" &gt;
        <activity>
            android:name=".MainActivity"
            android:label="@string/app_name" &gt;
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        &lt;!-- Google Map Key --&gt;

        &lt;meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAxgtuqq30RxWs0jUtq8X6BNgbA1bkehUY" &gt;
        &lt;/meta-data&gt;
    </application>

</uses-feature></uses-sdk></manifest>
Posted
Updated 12-Aug-14 21:11pm
v3
Comments
JoCodes 13-Aug-14 3:12am
   
Can u please let us know in detail whats the "trouble" caused?
Sandeep Londhe 13-Aug-14 3:47am
   
it is not running on Emulator opening the tab stating Get google play services your phone does not have it.
Sandeep Londhe 13-Aug-14 7:43am
   
it is not intalling on emulator and i dont have 4.2.2 right now

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Use the ADB install command to install com.android.vending-1.apk and com.google.android.gms-1.apk which needs to be configured in the Emulator.

Follow these links in case you face any issues,

http://umut.tekguc.info/en/content/google-android-map-v2-step-step[^] ( Step 7 onwards )

http://nemanjakovacevic.net/blog/english/2012/12/06/how-to-make-android-google-maps-v2-work-in-android-emulator/[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100