2013-05-16 33 views
4

我在活動中顯示地圖...但是當我在設備上運行應用程序時它不顯示任何東西,它只顯示白色屏幕並放大縮小選項... MAP關鍵是正確的..感謝..谷歌地圖不顯示任何東西在地圖中

AndroidManifest.xml中

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

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



    <permission android:name="com.edxample.finalmap.permission.MAPS_RECEIVE" 
     android:protectionLevel="signature" /> 
    <uses-permission android:name="com.edxample.finalmap.permission.MAPS_RECEIVE" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

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




    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.edxample.finalmap.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> 

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

    </application> 

</manifest> 

activity_main.xml中

<RelativeLayout 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" 
    tools:context=".MainActivity" > 

    <fragment 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     xmlns:map="http://schemas.andoid.com/apk/es-auto" 
     android:name="com.google.android.gms.maps.SupportMapFragment" /> 


</RelativeLayout> 

MainActivity

package com.edxample.finalmap; 

import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.GooglePlayServicesUtil; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 

import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 
import android.view.Menu; 
import android.widget.Toast; 

public class MainActivity extends FragmentActivity { 

    private GoogleMap googleMap; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     if(check()) 
     { 
      setContentView(R.layout.activity_main); 
      Toast.makeText(this, "In Google play service.", Toast.LENGTH_LONG).show(); 
      initFun(); 
     } 
     else 
     { 
      Toast.makeText(this, "Google play service not available.", Toast.LENGTH_LONG).show(); 
     } 
    } 


    private Boolean check() 
    { 
     int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this); 
     if(status==ConnectionResult.SUCCESS) 
     { 
      return true; 
     } 

     return false; 
    } 

    public void initFun() 
    { 
     SupportMapFragment sp = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 
     googleMap = sp.getMap(); 
     googleMap.setMyLocationEnabled(true); 
     googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); 


    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.activity_main, menu); 
     return true; 
    } 

} 
+0

你有沒有在你的android地圖項目中引用谷歌播放服務庫?並啓用https://code.google.com/apis/console – Raghunandan

+1

'「MAP key is right」映射API v2然後再次卸載並安裝應用程序。 –

+0

yap我引用了Android地圖項目中的Google Play服務庫。 Api鍵是釋放,我用這個項目創建(https://code.google.com/apis/console)..感謝您的重播.. –

回答

2

您的地圖API密鑰適用於您的調試版本或發佈版本嗎?關鍵是基於你的密鑰庫,這在你的調試和發佈構建中是不同的。如果您正在調試您的應用,您的Google地圖釋放鍵將不起作用,反之亦然。

+0

我使用的發佈API密鑰在這個項目中。感謝您的重播.. –

+0

但是你在發佈模式下運行應用程序?因爲如果你不是,它會像你說的那樣顯示一個空白屏幕。 –

+0

感謝重播..問題是...我創建地圖鍵上釋放模式,但在調試模式下運行應用程序...當使簽署.apk和運行在設備上的作品.. –

8

enter image description here

,因爲我已讓谷歌地圖API V2 on.It生成的密鑰我也有同樣的問題被用於網頁未針對移動。

對於Android設備,你必須做一個谷歌地圖在Android API V2和生成密鑰

+0

謝謝重播...我打開谷歌地圖android api v2 ...現在我的問題解決了..。使簽署.apk,因爲我使用釋放鍵... –

+0

是什麼問題? –

+0

我使用證書的指紋不調試密鑰工具,因此,使簽署的.apk比運行此簽名的apk上的設備,它的作品,在我運行調試模式之前,如果我通過調試鍵工具創建地圖鍵比地圖顯示在調試模式 –

10

用你的主包用於生成密鑰的名字。
例如: 即時我的項目,谷歌地圖v2是在com.ftravelbook.googlemapv2 但當生成密鑰,你必須使用你的主包的名字(com.ftravelbook) 這裏有一些截圖:
enter image description here enter image description here enter image description here

+0

感謝重播..問題是...我創建地圖鍵在發佈模式,但在調試模式下運行應用程序......當簽署.apk和運行在設備上的作品.. –