4

i am showing a map in activity ... but when i run app on device it does not show any thing , it show just white screen and zoom in zoom out options... MAP key is right .. thanks ..

AndroidManifest.xml

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

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



     <permission android:name="com.edxample.finalmap.permission.MAPS_RECEIVE"
         android:protectionLevel="signature" />
     <uses-permission android:name="com.edxample.finalmap.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" />

    <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" >
        <activity
            android:name="com.edxample.finalmap.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="AIzaSyBL8ANi3jKkM0tF65C_Qus2_JgWRzClhfU" />

    </application>

</manifest>

activity_main.xml

<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"
        xmlns:map="http://schemas.andoid.com/apk/es-auto"
        android:name="com.google.android.gms.maps.SupportMapFragment" />


</RelativeLayout>

MainActivity

package com.edxample.finalmap;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;

public class MainActivity extends FragmentActivity  {

    private GoogleMap googleMap;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if(check()) 
        {
            setContentView(R.layout.activity_main);
            Toast.makeText(this, "In Google play service.", Toast.LENGTH_LONG).show();
            initFun();
        }
        else
        {
            Toast.makeText(this, "Google play service not available.", Toast.LENGTH_LONG).show();
        }
    }


    private Boolean check()
    {
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
        if(status==ConnectionResult.SUCCESS)
        {
            return true;
        }

        return false;
    }

    public void initFun()
    {
        SupportMapFragment sp = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
        googleMap = sp.getMap();
        googleMap.setMyLocationEnabled(true);
        googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);


    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

}
mohsin raza
  • 665
  • 1
  • 7
  • 20
  • have you referenced google play services library in your android map project? and enabled maps api v2 in https://code.google.com/apis/console – Raghunandan May 16 '13 at 14:24
  • 1
    `"MAP key is right"` uninstall and install app again then. – MaciejGórski May 16 '13 at 14:43
  • yap i referenced google play services library in android map project. Api key is release that i use in this project created from (https://code.google.com/apis/console).. thanks for your replay .. – mohsin raza May 16 '13 at 14:46
  • thanks for replay .. problem is ... i am created map key on release mode but run app on debug mode ... when make signed .apk and run on device its works .. – mohsin raza May 17 '13 at 07:12
  • I recommend to remove your API key from your post – Thorsten Niehues Sep 04 '13 at 07:40

3 Answers3

10

Use your main packet name for generate key.
For example: im my project, google map v2 is in com.ftravelbook.googlemapv2 but when generate key, you must use your main packet name (com.ftravelbook) here are some screenshots:
enter image description here enter image description here enter image description here

Guido
  • 1,161
  • 3
  • 12
  • 33
Tai Dao
  • 3,407
  • 7
  • 31
  • 54
  • thanks for replay .. problem is ... i am created map key on release mode but run app on debug mode ... when make signed .apk and run on device its works .. – mohsin raza May 17 '13 at 07:11
8

enter image description here

I was also having the same problem because i have generated key by making on google maps api v2 on.It is used for web not for mobile.

For android device you have to make a google maps android api v2 on and generate your key

Singh Arjun
  • 2,454
  • 1
  • 16
  • 13
  • thanks for replay ... i turn on google maps android api v2 ... now my problem is solved .. . make signed .apk because i am using release key ... – mohsin raza May 17 '13 at 07:17
  • i use fingerprint of certificate not debug key-tools , due to this , make signed .apk than run this signed apk on device , its works , before i run debug mode , if i create map key through debug key-tools than map show in debug mode – mohsin raza May 17 '13 at 08:06
2

Is your map API key for your debugbuilds or your release builds? The key is based on your keystore, which is different between your debug and release build. Your release key for google maps won't work if you're debugging your app, and vice versa.

Sander van't Veer
  • 5,930
  • 5
  • 35
  • 50
  • But are you running the app in release mode? Cause if you're not, it will show a blank screen like you said. – Sander van't Veer May 16 '13 at 14:48
  • thanks for replay .. problem is ... i am created map key on release mode but run app on debug mode ... when make signed .apk and run on device its works .. – mohsin raza May 17 '13 at 07:13
  • @Sandervan'tVeer hey i am getting blank screen when we run the app in device whts my problem? – Google Jul 01 '13 at 10:15
  • make sure your certificate must be release , not debug and map key generate with release certificate .. – mohsin raza Jul 29 '13 at 10:17