简体   繁体   中英

Google Map API v2 Key

Is it complusary to create Map API Key after enabling the "Google Maps Android v2" ?? Because I tried alot but I always failed to run app of Google Map. Please tell me if anyone has tried this. Thanks.

Manifest.xml

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

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

 <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
   <permission
    android:name="com.anshul.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

   <uses-permission android:name="com.anshul.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.anshul.MapActivity"
        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="------removed-------" />
   </application>

   </manifest>

Yes, ofcourse its must necessary to create Google Map Api key, without it, how could you success to load the map. You must need to give that key to Android Manifest file's map api key attribute. ITS MUST NECESSARY.

Yes the API Key is compulsory, otherwise Google won't authorize your app to use maps.

https://developers.google.com/maps/documentation/android/start#get_an_android_certificate_and_the_google_maps_api_key

To get an API Key goto the Google API Console: https://code.google.com/apis/console/

Ensure "Google Maps Android API v2" is checked and then goto API Access and click "Create New Android Key...."

This allows you to enter your package name ie "com.example.whatever" and your SHA-1 fingerprint (which can be grabbed from eclipse or using keytool). All information can be found in the above link.

Good luck

This is only because of wrong SHA so use the following code to get the correct SHA of your project.

    try {

        PackageInfo info = getPackageManager().getPackageInfo(
                    "Your PAckage here", 
                        PackageManager.GET_SIGNATURES);
                for (Signature signature : info.signatures) {
                    MessageDigest md = MessageDigest.getInstance("SHA");
                    md.update(signature.toByteArray());
                    Log.d("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
    //              //              System.out.println("KEY HASH.........."+Base64.encodeToString(md.digest(), Base64.DEFAULT));
                }
            } catch (NameNotFoundException e) {
                System.out.println("name not found...."+e);
            } catch (NoSuchAlgorithmException e) {
                System.out.println("NoSuchAlgorithmException...."+e);
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM