2011-11-04 117 views
1

我試圖在我的應用程序上顯示一個基本的谷歌地圖,但這不起作用它顯示一個白色屏幕,而不是我有一個網絡連接,我也檢查我的MANEFIST一百次,我genub deubg鍵,並確定它是真的安卓空白頁上的谷歌地圖(白色)

我想如果有人可以帶領我什麼做錯了?

我也沒有修改代碼,但在EMULATOR上第二次顯示地圖並且在我的設備上它並不突然顯示在模擬器上的AT ALL上。



public class MyMapDisplayActivity extends MapActivity {

MapController MControl; 
GeoPoint GeoP; 
MapView mapview; 



/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

      //Map 
      MapView mapview = (MapView) findViewById(R.id.mapview); 
      mapview.displayZoomControls(true); 
      mapview.setBuiltInZoomControls(true); 

      double lat = 19.7888; 
      double longi = 52.535; 


      GeoP = new GeoPoint ((int) (lat *1E6),(int) (longi *1E6)); 


      MControl = mapview.getController(); 
      MControl.animateTo(GeoP); 
      MControl.setZoom(14); 




      MyLocationOverlay LocationOverlay = new MyLocationOverlay(this, mapview); 
      mapview.getOverlays().add(LocationOverlay); 
      LocationOverlay.enableCompass(); 
      LocationOverlay.enableMyLocation(); 
}//onCreate 

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





<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/tab2" 
     android:orientation="vertical" 
     android:paddingTop="60px" 
     > 
     <com.google.android.maps.MapView 
     android:id="@+id/mapview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:enabled="true" 
     android:clickable="true" 
     android:apiKey="0jiwJEbT6if6dhaf0x6Fr_zRLsrz_CYxcLGj6pQ" 
       /> 

</LinearLayout> 





<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
     package="jdisplay.map" 
     android:versionCode="1" 
     android:versionName="1.0"> 
    <uses-sdk android:minSdkVersion="8" /> 
      <uses-permission android:name="android.permission.INTERNET"></uses-permission> 
      <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <application android:icon="@drawable/icon" android:label="@string/app_name"> 
     <activity android:name=".BatteryprojectActivity" 
        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" /> 
     </application> 

</manifest> 
+1

你可以發佈你的清單,你的佈局和活動代碼? – Chiara

+0

編輯我的帖子提前致謝 – mabalowsho

回答

1

你必須創建兩個不同的API密鑰,一個與仿真器和一個調試簽名密鑰用你用來簽署設備apk的密鑰。

+0

我已經有兩個不同的鍵。 我剛剛在主內發佈了API調試密鑰。xml – mabalowsho

+0

只是說,因爲它不清楚你的問題。另一件事:最好在onResume方法中執行enablemylocation,並在onPause方法中執行disableMyLocation。 –

+0

您可以嘗試的另一件事是在LinearLayout的layout_height中更改fill_parent的wrap_content。 –

0

我認爲這兩點可能會對你有所幫助。我有類似的問題 -

  1. 嘗試在應用程序標記之後和活動標記之前放置uses-library行。這很重要,可能是因爲圖書館正在參加活動課。

  2. 如果這不能解決問題,請嘗試檢查您的API密鑰是否已正確生成。找到位於默認文件夾「C:\ Documents and Settings \\ Local Settings \ Application Data」中的SDK調試證書\ Android「並在Keytool命令中使用此位置路徑。您也可以將它複製到「C:\ android」,然後運行 'keytool.exe -list -alias androiddebugkey -keystore「C:\ android \ debug.keystore」-storepass android -keypass android'。無論哪種方式,路徑都需要正確指定。它確實創建了密鑰,但在運行應用程序時不加載地圖。在我重新創建關鍵字之後,我的地圖加載了一個jiffy。

0

調試關鍵 - 你可以用它來直接從Android Studio中調試應用程序或虛擬設備或通過USB將手機/平板電腦上使用谷歌地圖API的Eclipse。

發佈密鑰 - 您可以使用它來製作已簽名的apk文件,您可以將其安裝在任何其他設備上。

如果你想測試你的發佈密鑰,你需要創建你的應用程序的apk文件,並將其安裝在你的設備上 - 相信我這是100%肯定!

您無法使用釋放鍵進行調試(運行地圖)應用程序!

,這就是爲什麼它被稱爲調試和發佈:d