Google map not show any thing in map
Asked Answered
P

3

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;
    }

}
Phina answered 16/5, 2013 at 14:13 Comment(5)
have you referenced google play services library in your android map project? and enabled maps api v2 in code.google.com/apis/consoleFlashback
"MAP key is right" uninstall and install app again then.Lean
yap i referenced google play services library in android map project. Api key is release that i use in this project created from (code.google.com/apis/console).. thanks for your replay ..Phina
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 ..Phina
I recommend to remove your API key from your postCopacetic
C
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.

Craner answered 16/5, 2013 at 14:31 Comment(4)
But are you running the app in release mode? Cause if you're not, it will show a blank screen like you said.Partite
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 ..Phina
@Sandervan'tVeer hey i am getting blank screen when we run the app in device whts my problem?Chipman
make sure your certificate must be release , not debug and map key generate with release certificate ..Phina
S
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

Sabelle answered 17/5, 2013 at 6:12 Comment(1)
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 ..Phina
G
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

Glenn answered 16/5, 2013 at 16:17 Comment(2)
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 ...Phina
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 modePhina
C
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.

Craner answered 16/5, 2013 at 14:31 Comment(4)
But are you running the app in release mode? Cause if you're not, it will show a blank screen like you said.Partite
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 ..Phina
@Sandervan'tVeer hey i am getting blank screen when we run the app in device whts my problem?Chipman
make sure your certificate must be release , not debug and map key generate with release certificate ..Phina

© 2022 - 2024 — McMap. All rights reserved.