2010-09-30 95 views
1

我知道這個問題之前已經被問及回答,但在按照所有說明操作之後,我仍然遇到同樣的問題:我的Android應用程序中有一個MapView,但視圖僅顯示底層網格(和覆蓋),但不是地圖本身。Android谷歌地圖不顯示

我在Eclipse中構建項目,如果這有所作爲。

我有以下的AndroidManifest.xml文件

<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.myapplication" 
     android:versionCode="1" 
     android:versionName="1.0"> 
<application android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:name=".MyApplication" 
       android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar"> 
     <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"></uses-library> 

然後在我的殼,我跑以下命令: $ keytool -list -alias androiddebugkey -keystore ~/.android/debug.keystore -storepass android -keypass android

,並得到了以下的輸出: androiddebugkey, Sep 23, 2010, PrivateKeyEntry, Certificate fingerprint (MD5): DF:69:80:83:16:1A:F0:E9:B9:07:B9:BD:F7:BC:DB:61

我去了http://code.google.com/android/maps-api-signup.html並將值DF:69:80:83:16:1A:F0:E9:B9:07:B9:BD:F7:BC:DB:61填入表格中,並得到以下API密鑰:0peT6kQ21Tpd1Rs61gBHHtquJwDcNeKkqedT08g

我RES /佈局/ main.xml中的文件看起來是這樣的:

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

而且我MyApplication.java文件看起來像: 包com.example.myapplication;

import android.os.Bundle; 

import com.google.android.maps.MapActivity; 

public class MyApplication extends MapActivity { 

    @Override public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
    } 

    @Override protected boolean isRouteDisplayed() { 
     return false; 
    } 
} 

我部署使用Eclipse的項目,我的AVD與谷歌API 2.1 UPDATE1兼容。我檢查,以確保該項目的簽署,並$ jarsigner -verify -verbose ~/workspace/MyApplication/bin/MyApplication.apk返回下面的輸出命令:

 
sm  2200 Thu Sep 30 12:42:16 EDT 2010 res/drawable/icon.png 
sm  676 Thu Sep 30 12:42:16 EDT 2010 res/layout/main.xml 
sm  1796 Thu Sep 30 12:42:16 EDT 2010 AndroidManifest.xml 
sm  1968 Thu Sep 30 12:42:16 EDT 2010 resources.arsc 
sm  7816 Thu Sep 30 12:42:16 EDT 2010 classes.dex 
     646 Thu Sep 30 12:42:16 EDT 2010 META-INF/MANIFEST.MF 
     699 Thu Sep 30 12:42:16 EDT 2010 META-INF/CERT.SF 
     776 Thu Sep 30 12:42:16 EDT 2010 META-INF/CERT.RSA 

    s = signature was verified 
    m = entry is listed in manifest 
    k = at least one certificate was found in keystore 
    i = at least one certificate was found in identity scope 

我給的AVD的應用大約有10分鐘時間來加載地圖圖像和我沒有變任何東西。該adb logcat沒有報告任何異常:

 
I/ActivityManager( 56): Starting activity: Intent { cmp=com.example.myapplication/.MyApplication } 
E/ActivityThread( 259): Failed to find provider info for com.google.settings 
E/ActivityThread( 259): Failed to find provider info for com.google.settings 
W/MapActivity( 259): Recycling dispatcher [email protected] 
V/MapActivity( 259): Recycling map object. 
I/ActivityManager( 56): Displayed activity com.example.myapplication/.MyApplication: 376 ms (total 376 ms) 

任何人都可以找出我在做什麼錯在這裏?任何意見,將不勝感激。謝謝。

+0

您是否使用Google API版本運行模擬器,而不是正常版本?你的模擬器有互聯網連接嗎?谷歌地圖應用程序的工作? – Falmarri 2010-09-30 17:26:20

+0

是的,這是Google API,而不是普通版本。我不確定如何測試AVD的互聯網連接。但我看了一下地圖應用程序 - 一些地圖被加載。如果我滾動瀏覽地圖,我會看到地圖,但是如果我向上,向下,向左或向右滾動得太遠,我只能看到下面的網格(它不會加載地圖的其餘部分)。 – jay 2010-09-30 17:42:40

回答

0

我關閉了模擬器並重新啓動它,現在它工作正常。我注意到新的模擬器具有「3G」符號,並且顯示手機接收的圖標有兩個小節。 (舊的模擬器沒有3G或1G符號,也沒有任何條形碼。)也許這有所作爲......?

+0

是的,這是有所作爲。當模擬器啓動時,它會嘗試確定當時是否有Internet連接。如果你這樣做,它的行爲正常,你有3G圖標和2條信號。但是,如果仿真器沒有檢測到互聯網連接,它將表現得好像根本沒有連接(數據或語音),您將得到0條信號。即使您清除了主機上的任何Internet問題,這種情況也會持續存在。重新啓動模擬器是我所知道的唯一解決方案。在0酒吧狀態下,互聯網接入將不起作用。 – CommonsWare 2010-09-30 19:15:27

+0

以我的經驗,這是一個模擬器的錯誤。我一直都在上網,但模擬器似乎想要不時上網而不需要互聯網。重新啓動它可以修復它。 – ShadowGod 2010-10-01 07:32:56

4

添加Internet權限清單...

所有的
<uses-permission android:name="android.permission.INTERNET" /> 
0

添加下面的標籤在android系統manifest.xml文件中的應用程序標籤,即,

<uses-permission android:name="android.permission.INTERNET" /> 
    <application 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" > 

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

而且還使用自定義調試密鑰庫。轉到窗口選擇偏好,然後在android下選擇生成。