0

i am trying to display or see google maps on my app.

  1. I have added the library google_play_services_lib(no error).
  2. Obtain a google maps api key.
  3. Follow the code in http://www.vogella.com/tutorials/AndroidGoogleMaps/article.html#overview_intro (no error).
  4. But run the app in emulator, it stopped. it says "Unfortunately ShowMapActivity has stopped ".

i am not getting any error. i think problem is in xml file.fragment is not working. what should i do now. plz help me with this or give me simple sample project using google map. i am beginner at google map in android and trying badly to fix it but......:(

here is the activity_main.xml 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/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.MapFragment" />

     </RelativeLayout> 

MainActivity.java file :

    package com.vogella.android.locationapi.maps;

    import android.app.Activity;
    import android.os.Bundle;
    import android.view.Menu;

    import com.google.android.gms.maps.CameraUpdateFactory;
    import com.google.android.gms.maps.GoogleMap;  
    import com.google.android.gms.maps.MapFragment;
    import com.google.android.gms.maps.model.BitmapDescriptorFactory;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.Marker;
    import com.google.android.gms.maps.model.MarkerOptions;

    public class MainActivity extends Activity {
    static final LatLng HAMBURG = new LatLng(53.558, 9.927);
    static final LatLng KIEL = new LatLng(53.551, 9.993);
    private GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    /*map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
    .getMap();
    Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
    .title("Hamburg"));
    Marker kiel = map.addMarker(new MarkerOptions()
    .position(KIEL)
    .title("Kiel")
    .snippet("Kiel is cool")
    .icon(BitmapDescriptorFactory
        .fromResource(R.drawable.ic_launcher)));

    // Move the camera instantly to hamburg with a zoom of 15.
    map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

    // Zoom in, animating the camera.
    map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
    */  }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
    }
    }

and AndroidManifest.xml file:

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

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

<permission
    android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<uses-permission  android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<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="com.vogella.android.locationapi.maps.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.AIzaSyADyrVyRG68lvuQ0721D_Iaw0VLaeMjNuA"
        android:value="AIzaSyADyrVyRG68lvuQ0721D_Iaw0VLaeMjNuA" />
</application>

 </manifest> 
Patriotic
  • 2,103
  • 4
  • 26
  • 36
  • You can try the code from http://www.myandroidsolutions.com/2014/06/25/android-google-maps-api-v2/, it explains all the steps. – Laura Jun 27 '14 at 12:21
  • alex is right, i made 3 apps using Google Map and if you still find problem ask me on this [room](http://chat.stackoverflow.com/transcript/message/17407246#17407246) – nawaab saab Jun 27 '14 at 12:29
  • check my answer here http://stackoverflow.com/questions/19094787/map-not-getting-in-emulator-android-api-v2/19317114#19317114 – Shailendra Madda Jun 28 '14 at 05:23
  • please post your Logcat.. – Lal Jun 29 '14 at 16:21

3 Answers3

1

Replace your meta-data in AndroidManifest.xml file with this one.

<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyADyrVyRG68lvuQ0721D_Iaw0VLaeMjNuA" />

also add this meta-data too.

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

Hope this will solve your problems.

Alex Chengalan
  • 8,211
  • 4
  • 42
  • 56
1

Most importantly you have to run the application in a real device not in emulator. Emulator does not have google play service installed if you don't have any real device try to run your application in Genymotion's emulator after installing google play service.

You can check Running Google Maps v2 on the Android emulator.

you need to change

<meta-data
     android:name="com.google.android.maps.v2.API_KEY"
     android:value="AIzaSyADyrVyRG68lvuQ0721D_Iaw0VLaeMjNuA" />

add this inside application tag

<meta-data
      android:name="com.google.android.gms.version"
      android:value="@integer/google_play_services_version" />
Community
  • 1
  • 1
Kaushik
  • 6,150
  • 5
  • 39
  • 54
0

I'm posting my map fragment as a reference. You can add the missing attributes and see if it's working.

<fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/transparent"
    map:cameraZoom="11" />
Lev
  • 443
  • 1
  • 4
  • 14