2013-04-01 20 views
2

我正在創建一個使用谷歌地圖api v2的android應用程序。 我相信我已經做了所有的谷歌教程賽斯,但我仍然只得到谷歌地圖網格(沒有地圖)。我使用keystore.debug的SHA1創建了一個調試密鑰。與谷歌地圖顯示網格android api

下面

是我的設置: Eclipse的Java編譯器1.7版 項目的Java編譯器1.6版

應用程序清單:

<manifest ...> 
    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="8" /> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="my.app.test.permission.MAPS_RECEIVE"/> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true"/> 

    <application> 
     <activity> 
     ... 
     </activity> 
     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="xxxxxxxxxxxxxxxxxxxxxxxxxx"/> 

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

</manifest> 

地圖xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/BackGroundColor" 
    android:orientation="vertical" 
    tools:context=".test" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:paddingRight="10dp" 
     android:paddingTop="5dp" > 

     <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="xxxxxxxxxxxxxxxxxxxxxxxxxx" > 
     </com.google.android.maps.MapView> 

    </LinearLayout> 
</LinearLayout> 

地圖活動:

public class Map extends MapActivity { 
MapView mapView; 
MapController mc; 
     GeoPoint p; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    requestWindowFeature(Window.FEATURE_NO_TITLE); 
    setContentView(R.layout.activity_map); 

    mapView = (MapView) findViewById(R.id.mapview); 
       mapView.setBuiltInZoomControls(true); 
       mapView.setStreetView(true); 


       mc = mapView.getController(); 
       String coordinates[] = {"1.352566007", "103.78921587"}; 
       double lat = Double.parseDouble(coordinates[0]); 
       double lng = Double.parseDouble(coordinates[1]); 

       p = new GeoPoint(
         (int) (lat * 1E6), 
         (int) (lng * 1E6)); 

       mc.animateTo(p); 
       mc.setZoom(17); 
       mapView.invalidate(); 
} 

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

}

我知道有很多帖子都有同樣的問題。我已閱讀他們所有! 我已經多次創建密鑰,但仍然是一樣的... 任何想法是什麼錯誤,我只看到網格?該應用程序與AVD以及Android 2.2.1版本的三星手機具有相同的結果。

+0

你肯定生成的密鑰不正確,這是這個問題的主要原因,您需要按照所有步驟從頭開始再次生成密鑰。 – Shehabix

+0

我以許多不同的方式多次生成密鑰。我還安裝了jdk 1.6,以便從該版本創建密鑰,因爲我已閱讀了一些關於此的帖子。密鑰生成有可能出錯了嗎? – Reven

+0

我也嘗試創建自己的證書,從該證書的sha1創建一個新密鑰並簽署/導出apk。然後我將應用程序安裝到我的android手機上。我仍然只用網格和縮放面板獲得空白地圖。因此,我傾向於認爲代碼有什麼問題......任何想法? – Reven

回答

2

如果你寫你的申請API V2則使用了錯誤的對象,你需要一些東西來解決:

刪除此:

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

這是Google Map API V1的許可。

2.你必須添加此2個權限:

<permission android:name="your.application.package.permission.MAPS_RECEIVE" android:protectionLevel="signature"/> 
<uses-permission android:name="your.application.package.permission.MAPS_RECEIVE"/> 

變化:your.application.package到當前的應用程序包。

3.當你瞄準SDK v8,你必須片段支持添加到您的應用程序,以便使用從谷歌地圖API V2的SupportMapFragment,所以你需要添加google-support-v4和更改地圖對象SupportMapFragment

4.您的MapActivity必須更改爲FragmentActivity

5.你可以可以得到關於如何在一篇博客文章中我就如何谷歌地圖API V2添加到您的項目中寫這些更改的詳細信息:

Google Maps API V2

+0

謝謝,我會試試看... – Reven

+0

感謝隊友,這是做的伎倆... – Reven

+0

你歡迎@Reven :) –

1

你的問題是與模擬器相關,你需要安裝到APK的。 我有類似的問題,所以我準備了一步一步的教程,以顯示如何使用谷歌地圖Android模擬器(Android 4.2.2)看看我的博客:http://umut.tekguc.info/en/content/google-android-map-v2-step-step

+0

儘管我的問題已經得到解答,但感謝本教程。這很好。 – Reven

相關問題