5

我为第二版创建了一个 Google API 密钥并在清单中使用了它,但我无法在设备上显示地图。

我遵循了谷歌地图文档中提供的所有内容。我也使用了这个链接

MainActivity.java。

包 com.example.googlenewmap;

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;

    import com.google.android.gms.maps.GoogleMap;
    import com.google.android.gms.maps.SupportMapFragment;
    import com.google.android.gms.maps.model.BitmapDescriptorFactory;
    import com.google.android.gms.maps.model.LatLng;
    import com.google.android.gms.maps.model.MarkerOptions;

    public class MainActivity extends FragmentActivity {
        static final LatLng HAMBURG = new LatLng(53.558, 9.927);
        static final LatLng KIEL = new LatLng(53.551, 9.993);
        private GoogleMap map;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);

            map = ((SupportMapFragment) getSupportFragmentManager()
                    .findFragmentById(R.id.map)).getMap();

            if (map != null) {
                map.addMarker(new MarkerOptions().position(HAMBURG)
                        .title("Hamburg"));
                map.addMarker(new MarkerOptions()
                        .position(KIEL)
                        .title("Kiel")
                        .snippet("Kiel")
                        .icon(BitmapDescriptorFactory
                                .fromResource(R.drawable.ic_launcher)));
            }

        }

    }

清单文件

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

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

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

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

        <!-- Copied from Google Maps Library/AndroidManifest.xml. -->
        <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" />

        <!-- External storage for caching. -->
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

        <!-- My Location -->
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <!-- Maps API needs OpenGL ES 2.0. -->
        <!-- Maps API needs OpenGL ES 2.0. -->

        <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true" />
        <!-- End of copy. -->

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <uses-library android:name="com.google.android.maps" />
            <!--
             ** You need to replace the key below with your own key. **
             The example key below will not be accepted because it is not linked to the
             certificate which you will use to sign this application.
             See: https://developers.google.com/maps/documentation/android/start
             for instructions on how to get your own key.
            -->

            <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="api key" />

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

    </manifest>

我该如何解决这个问题?

4

1 回答 1

1

你用的是什么钥匙?

键有调试键和释放键两种。在签署 apk 时,您想使用发布密钥。为此,您想将其与签名的 apk 进行比较

步骤1:

例如,您的 apk 名称是 A,并且您正在为 A.apk 签名并创建密钥库,即 A.keystore 将在某个驱动器位置创建。让我们在 E 驱动器中考虑它。

第2步:

现在定位到C盘中的jdk(考虑windows并分配C盘)

C:\Program Files\Java\jdk1.7.0\bin>keytool -list -v -keystore E:\A.keystore -alias A

所以它会创建 SHA-1 指纹

调试键是正常的,您照常提取。

于 2013-07-19T09:57:24.077 回答