Question

I do all the steps, I add google-play-sevices to my project,I do everything .I don't what's the problems.I create my api key using debug certificate fingerprint using SHA1 fingerprint in eclipse windows>preferences>android; I'm using lg E400 con android 2.3.6

MainActivity:

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


import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;

public class MainActivity extends Activity {
  GoogleMap map;
  MapView m;
  com.google.android.gms.maps.Projection projection;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     m=(MapView) findViewById(R.id.mapview);
    m.onCreate(savedInstanceState);
    map = m.getMap();
    if (map != null) {
        // The Map is verified. It is now safe to manipulate the map.

    }else{
        // check if google play service in the device is not available or out-dated.
        GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);

        // nothing anymore, cuz android will take care of the rest (to remind user to update google play service).
    }

    try{map.getUiSettings().setMyLocationButtonEnabled(false);
    map.setMyLocationEnabled(true);
    }catch(Exception ex){ex.printStackTrace();}

    MapsInitializer.initialize(this);

}
@Override
public void onResume() {

    super.onResume();
    m.onResume();
}
@Override
public void onDestroy() {
    super.onDestroy();
    m.onDestroy();
}
@Override
public void onLowMemory() {

   super.onLowMemory();
   m.onLowMemory();
}
 @Override
public void onSaveInstanceState(Bundle outState){
    super.onSaveInstanceState(outState);
     m.onSaveInstanceState(outState);
  }
}

layout:

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


<com.google.android.gms.maps.MapView
android:id="@+id/mapview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

</RelativeLayout>

manifest:

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

android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="9"
    android:targetSdkVersion="15" />

<permission
    android:name="com.example.voicesee.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.voicesee.permission.MAPS_RECEIVE" />
<!-- Copied from Google Maps Library/AndroidManifest.xml. -->
<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"  />                                                   
<!-- 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"/>
<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" >
   <meta-data
   android:name="com.google.android.gms.version"
   android:value="@integer/google_play_services_version" />


    <activity
        android:name="com.example.voicesee.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="AIzaSyAguDjIFiVWi18ll7Yh0oa8C7hWju1PUzI"/>


</application>

thanks for help!!

Was it helpful?

Solution

I had a similar problem, my issue was because I was picking the wrong debug keystore. I am working with an ubuntu machine. Since I opened eclipse as root, the default keystore in eclipse was located in my root folder(/root/.android/.android/debug.keystore) whiles I was creating the api key with the debug keystore from my user folder. I have added a link to the answered question: Google Maps V2 shows blank screen on android 2.2

OTHER TIPS

are you sure: your project in Google Console turn on the

Google Maps Android API v2

First, I don't understand why are you using a MapView when you are placing you map in the Acitivity because it's the harder way to display the map when you do so, Google's documentation states:

For a simpler method of displaying a Map use MapFragment (or SupportMapFragment) if you are looking to target earlier platforms.

Second, If you already do so, then you made some mistakes in implementing it because you place the:

MapsInitializer.initialize(this);

method in the wrong place, as the documentation states:

Use this class to initialize the Google Maps Android API if features need to be used before obtaining a map. It must be called because some classes such as BitmapDescriptorFactory and CameraUpdateFactory need to be initialized.

You will want to use a fragment to encase your map, and fragments are only supported by Android API levels 11 and up (3.0 and up). This is likely the cause of your problem.

As mentioned here, you need to use SupportMapFragment for your API version.

Here is the link to learn how to use it.

If that doesn't work, my guess is the API key. We had a situation before where the grid and the zoom buttons loaded and not the map, and the key was the culprit. I'd walk through the steps here to make sure you have done everything correctly (including using google play services)

In my code , i change mapview with supportMapfragment , i delete my previous debug.keytool and rebuilt it then i delete my old apikey and create a new key .It seems that my problem was the connection with google play service because it works after adding GooglePlayServicesUtil.isGooglePlayServicesAvailable() and verify the connection with google play services before calling setContentview()

once check your api key in manifest and SHA key of your application.. You can create new one by going to console.developers.google.com.

To see SHA key eclipse go to --> windows>preferences>select android on left panel>click on build

To see SHA key android studio see this link How to get the SHA-1 fingerprint certificate in Android Studio for debug mode?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top