它向我显示“服务器上的身份验证失败”错误。
应用程序运行时没有崩溃,但地图为空。下面我粘贴了项目的logcat和MainActivity类。

这是我项目的MainActivity

        static final LatLng TP = new LatLng(17.385044, 78.486671);
        private GoogleMap googleMap;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            try {
                // Loading map
                initilizeMap();

            } catch (Exception e) {
                e.printStackTrace();
            }
            /*
             * try { if (googleMap == null) { googleMap = ((MapFragment)
             * getFragmentManager() .findFragmentById(R.id.map)).getMap(); }
             * googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
             * googleMap.addMarker(new MarkerOptions().position(
             * TP).title("TP")); } catch (Exception e) {
             * e.printStackTrace(); }
             */
        }

        @Override
        protected void onResume() {
            // TODO Auto-generated method stub
            super.onResume();
            initilizeMap();
        }

        /* function to load map. If map is not created it will create it for you */
        private void initilizeMap() {
            if (googleMap == null) {
                googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                        R.id.map)).getMap();

                // check if map is created successfully or not
                if (googleMap == null) {
                    Toast.makeText(getApplicationContext(),
                            "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                            .show();
                }
            }
        }
    }

     ## Manifest ##

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

        <uses-permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE" />

        <uses-sdk
            android:minSdkVersion="14"
            android:targetSdkVersion="22" />

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

        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="com.google.android.providers.gsf.permission.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" />

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".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>

            <uses-library android:name="com.google.android.maps" />

            <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />
            <!-- Google MAP API key -->
            <meta-data
                android:name="com.google.android.geo.API_KEY"
                android:value="AIzaSyA4cNBwKoRxmpW0qhMF8B_jBDpkkHaaSsQ" />
        </application>

    </manifest>


这是logcat:

01-05 11:34:22.841: E/b(24238): Authentication failed on the server.
        01-05 11:34:22.841: E/Google Maps Android API(24238): Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
        01-05 11:34:22.851: E/Google Maps Android API(24238): In the Google Developer Console (https://console.developers.google.com)
        01-05 11:34:22.851: E/Google Maps Android API(24238): Ensure that the "Google Maps Android API v2" is enabled.
        01-05 11:34:22.851: E/Google Maps Android API(24238): Ensure that the following Android Key exists:
        01-05 11:34:22.851: E/Google Maps Android API(24238):   API Key: AIzaSyA4cNBwKoRxmpW0qhMF8B_jBDpkkHaaSsQ
        01-05 11:34:22.851: E/Google Maps Android API(24238):   Android Application (<cert_fingerprint>;<package_name>): 90:A8:E0:F0:90:2F:93:73:C6:16:F0:10:B7:D8:2B:8A:24:08:48:7E;com.cell.track.activity

最佳答案

请确保您已在清单中添加了地图API密钥。
如果您已正确创建api密钥,请确保已从开发人员控制台启用了google maps api。
 我创建了一个方案,其中所有情况都正确,除非未启用。显示与您相同的错误。希望能帮助到你。

07-27 17:14