Will
Will

Reputation: 111

Imposible to develop a simple android app using Google Map API V2

I would like to use a Google Map in my current application. Before integrate it to my app, I created a test project to understand the functionalities.

I read this : https://developers.google.com/maps/documentation/android/start#installing_the_google_maps_android_v2_api

and this : http://developer.android.com/google/play-services/setup.html#

After a lot of problems with these errors :

didn't find class com.google.android.gms.maps.MapFragment

and

Found 2 versions of android-support-v4.jar in the dependency list, but not all the versions are identical (check is based on SHA-1 only at this time)

When I run my project, Eclipse says "Launching Test:(99%)", then my computer temperature up to 100°C and Eclipse take 512% of my CPU ! So I'm obliged to force Eclipse to quit.

I spent a lot of time on stack overflow, rebuild, clean, add support library, delete project and recreate from the beginning etc. Help me, I just want to create a basic app to test a GoogleMap !

My code :

MainActivity.java

public class MainActivity extends Activity {

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

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>

manifest

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="21" />

    <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" />
    <!--
     The following two permissions are not required to use
     Google Maps Android API v2, but are recommended.
    -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <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>

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

</manifest>

Edit : I know now that the problem appears when I reference the google-play-services_lib to my project... Any ideas ?

Upvotes: 0

Views: 415

Answers (2)

chiru
chiru

Reputation: 645

Even me having the same issue, then instead of getting API key from Google Map Android V2, i took the API key from Google Maps Embed API and included in the Manifest and solved my problem.

Proof: 1.API key i took for project API Key Used 2.Used Key in Manifest.xml enter image description here

Upvotes: 1

IntelliJ Amiya
IntelliJ Amiya

Reputation: 75788

public class YourActivity extends FragmentActivity {

   GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.your_activity);
        map =((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.iqamah_map)).getMap();

    }
}

your xml :

 <?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/iqamah_map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.SupportMapFragment" />

Add this in your Manifest

    <uses-permission android:name="com.example.test.permission.MAPS_RECEIVE" />
 <uses-library android:name="com.google.android.maps" />

Upvotes: 1

Related Questions