2013-03-13 63 views
2

這些都是我下面生成我的Android地圖的關鍵步驟:產生的Android谷歌地圖鍵 - 一步一步

1)我執行以下命令:

keytool -list -v -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android

這命令將作爲輸出是這樣的:

Alias name: androiddebugkey 
Creation date: Mar 13, 2013 
Entry type: PrivateKeyEntry 
Certificate chain length: 1 
Certificate[1]: 
Owner: CN=Android Debug, O=Android, C=US 
Issuer: CN=Android Debug, O=Android, C=US 
Serial number: 51401a0b 
Valid from: Wed Mar 13 02:17:47 EDT 2013 until: Fri Mar 06 01:17:47 EST 2043 
Certificate fingerprints: 
    MD5: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX 
    SHA1: XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX 
    Signature algorithm name: SHA1withRSA 
    Version: 3 

2-)獲得SHA1後,我把它複製,然後我打開此鏈接:https://code.google.com/apis/console/

我設置此功能:

enter image description here

3-),該後我生成新的密鑰:

哪裏XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX:XX(是edu.osu.cse5326.busstopapp上述得到的SHA1),並且是單包我的項目。

enter image description here

4-)最後,我複製生成的地圖API密鑰:

enter image description here

5)我貼到我的佈局之一:

<com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" 
        android:id="@+id/mapViewBusStopLocation" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:clickable="true" 
        android:apiKey="the_api_key" 

       /> 

6-)我從相應的Activity中加載地圖。

7-)這是我的manifest.xml文件:

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

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.CAMERA" /> 

    <uses-feature android:name="android.hardware.camera" /> 
    <uses-feature android:name="android.hardware.camera.autofocus" /> 

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

    <permission 
     android:name="edu.osu.cse5326.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 

    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true" /> 

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

    <application 
     android:name="edu.osu.cse5326.busstopapp.AppState" 
     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" /> 

     <activity 
      android:name="edu.osu.cse5326.busstopapp.LoginActivity" 
      android:label="@string/app_name" > 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 

     Many other activities 
    </application> 

</manifest> 

的問題的是,我只看到灰色地帶,沒有地圖信息。

這是試圖運行項目的時候,我發現了異常:

03-13 16:48:28.045: W/System.err(375): IOException processing: 26 
03-13 16:48:28.045: W/System.err(375): java.io.IOException: Server returned: 3 
03-13 16:48:28.045: W/System.err(375): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115) 
03-13 16:48:28.045: W/System.err(375): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473) 
03-13 16:48:28.045: W/System.err(375): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117) 
03-13 16:48:28.055: W/System.err(375): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994) 
03-13 16:48:28.055: W/System.err(375): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702) 
03-13 16:48:28.055: W/System.err(375): at java.lang.Thread.run(Thread.java:1019) 
03-13 16:48:28.365: W/System.err(375): IOException processing: 26 
03-13 16:48:28.365: W/System.err(375): java.io.IOException: Server returned: 3 
03-13 16:48:28.365: W/System.err(375): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115) 
03-13 16:48:28.375: W/System.err(375): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473) 

我一直在閱讀了很多,我認爲這是與地圖API密鑰的一個問題,但我不能找到我做錯了什麼。

事情我都試過,不工作:

  1. 刪除debug.keystore和遍佈再次生成。
  2. 我嘗試在真實的設備上運行,而不是仿真器。
  3. 重新生成map api key並等待幾個小時以查看是否需要時間才能工作。
+1

'<許可 機器人:名字=「COM .example.mapdemo.permission.MAPS_RECEIVE「 android:protectionLevel =」signature「/> ' 您是否已將此項添加到清單? – abbath 2013-03-13 23:04:05

+0

謝謝@abbath,讓我編輯我的問題來添加我的manifest.xml信息。 – 2013-03-13 23:04:52

+0

您是否嘗試過使用[此處](https://developers.google.com/maps/documentation/android/start))的片段方式? – abbath 2013-03-13 23:10:24

回答

4

我不明白,您使用的是谷歌地圖API V2在您的所有設置,包括您從控制檯拿到鑰匙,但您使用的是MapView對象,它是谷歌地圖API V1對象。

根據您正在編寫應用程序的minSDK,您應該使用MapFragmentSupportMapFragment對象與android-support-v4庫。

這裏是一個博客帖子我就如何在谷歌地圖API V2添加到您的應用程序寫的,我想你會發現它很方便:

Google Map API V2

+0

謝謝!那我應該用什麼?分段? – 2013-03-13 23:27:01

+0

查看更新的答案。 – 2013-03-13 23:31:12

+0

你的教程的這一行給我一個錯誤:「xmlns:map =」http://schemas.android.com/apk/res-auto「,錯誤:意外命名空間前綴」xmlns「發現標記 片段... .. – 2013-03-14 00:19:03

1

我搜索了一下,發現this的問題,這樣的回答:

When using the signed API key, the MapView will show up ONLY when the app is installed from the Android Market. So, installing the app from Eclipse (Run As, Debug As, etc) or command line (adb install) won't show the MapView. Rest assured, once the app is in the Market - you download it and the MapView will show up.

這是一個有點怪異,但我希望它會幫助你。

+0

我認爲這只是「生產」鍵的情況,我只是試圖安裝一個調試密鑰來開始開發應用程序...... .. – 2013-03-13 23:20:46

+0

您正在使用舊的'com.google.android.maps.MapView'而不是'com.google.android.gms.maps.MapView'。這可能是一個問題嗎? – abbath 2013-03-13 23:34:59