0

I am trying to embed Google Maps into my app. Below is my xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" >
    <fragment
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        class="com.google.android.gms.maps.SupportMapFragment"/>

</LinearLayout>

Here is the main class file:

package com.em.basicmap;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

public class MainActivity extends FragmentActivity {

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

Here is my manifest file:

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

    <permission android:name="com.em.MAPS_RECIEVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="com.em.MAPS_RECIEVE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.READ_PHONE_STATE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permissions.READ_GSERVICES"/>
    <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"/>
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.em.basicmap.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="AIzaSyCrstFrx_Mj8PaBJYtSH6bk62kggzstYzM"/>
    </application>

</manifest>

I have tried everything I can think of. I have made sure that I have Google Maps Android API in the google apis. I have renewed my debugging key many times, I have downloaded the google-play services and I have copied the lib jar into my directory. I have ensure that my target sdk is Google api 17, I have included all of the permissions that I could find that I might need. I've looked all over StackOverflow for help, and the above are the help that I could find, but my app still displays a blank screen and zoom buttons. I'm really at a loss for what to do now. Are there some other things I have not done correctly? How might my access my SHA1 code? I have done it through the command line and eclipse, but my logcat says that it may still be an authorization issue.

Sourabh Saldi
  • 3,567
  • 6
  • 34
  • 57
  • are you running your app in emulator or on device? and have you created debug key or signed apk key?? – Pratik Dasa Oct 22 '13 at 04:30
  • @lonelyminstrel Have you on the `Google Map v2` service in your google console ? – GrIsHu Oct 22 '13 at 04:43
  • here is great tutorial on this subject http://blog.enbake.com/integrating-google-maps-api-v2-with-android-application/ compare each step and check if you have missed any cheers!! – Sourabh Saldi Oct 22 '13 at 04:44
  • I am running my app on a device, does it work on emulators? I have Google Maps Android API v2 service on in my console. I did create a key, a few times, but I may be creating it wrong. I tried using the command line, and I also tried using eclipse to find it. – lonelyminstrel Oct 22 '13 at 15:59

4 Answers4

0
public class MapsActivity extends FragmentActivity
{
GoogleMap gm;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
    setContentView(R.layout.maps);
gm = ((SupportMapFragment) (getSupportFragmentManager()
            .findFragmentById(R.id.map))).getMap();
gm.setMapType(GoogleMap.MAP_TYPE_NORMAL);
gm.setMyLocationEnabled(true);

} }

There are two keys.Debug and release key. Release key procedure,you can refer here.

Google Map Android API v2 can't display map in play store application

Community
  • 1
  • 1
Shadow
  • 6,864
  • 6
  • 44
  • 93
0

In your MainActivity you will have to load the GoogleMap. Just putting fragment in xml file doesn't going to load the map.

Try out as below:

public class MainActivity extends FragmentActivity {
 private GoogleMap mMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

   // Do a null check to confirm that we have not already instantiated the map.
        if (mMap == null) {
            // Try to obtain the map from the SupportMapFragment.
            mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
                    .getMap();
            // Check if we were successful in obtaining the map.
            if (mMap != null) {
                  mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
            }
        }
    }
}
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
0

Your manifest looks right. It's definitely a problem with your key.

In the api console, under services, make sure you have selected Google Maps Android API v2 and not Google Maps API v3. Also, make sure you have appended your package name to your key and that your are generating your SHA-1 on the same key that you are signing with. If this is debug mode, use:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore -list -v

If release mode use your release keystore.

cgould
  • 134
  • 5
0

So it is problem with your API key, create new API key with your SHA-1 key and package name(mentioned in Android manifest.xml) separated with semi column.

See here,just change the api key with your key in manifest file and follow these steps:
and make sure that your google_play_services_lib project should be present in your project's work space only.

Manifest file:

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

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

    <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="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.geeklabs.map.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="replace with your API key"/>

    </application>

</manifest>

MainActivity.java:

    package com.geeklabs.map;

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

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"/>

After got this let me know.

Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138