2013-07-19 43 views
5

我已經爲第二版創建了一個Google API密鑰,並在清單中使用了它,但我無法在設備上顯示地圖。我爲V2創建了Android Map API密鑰,無法顯示地圖

我遵循谷歌地圖文檔中提供的一切。我也用this link

MainActivity.java。

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

我怎樣才能解決這個問題呢?

+0

什麼是你的佈局XML文件的樣子?你得到的錯誤是什麼? – Sean

+0

無需擴展'FragmentActivity'擴展標準'Activity'。不需要使用'SupportMapFragment'。使用'MapFragment'。因爲你的minsdk是14而不是11並且低於 – Raghunandan

+0

@Raghunandan謝謝你的回覆,但我已經使用過了,但那不起作用 – Michel

回答

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一個

因此,這將創建SHA-1指紋

調試關鍵是正常的,你提取如常。

+0

好的!讓我嘗試!此陰影 – Michel

+0

無法獲得與應用程序相關的密鑰庫文件可以請告訴我在哪裏我會得到它 – Michel

+0

keystore文件是你正在創建自定義簽名的apk.file-> export-> Android-> export android應用程序 - >特定項目名稱>跳到下一個 - >然後瀏覽位置並使用.keystore進行擴展,並填寫密碼和一些要求等,以便將該密鑰庫與地圖進行比較。 – Shadow

相關問題