2014-06-27 131 views
0

谷歌地圖不加載,並給出一個空白屏幕 嘗試了一些指南,並試圖谷歌的指導,但沒有一個似乎工作 這就是我全部有加,不可能發現一個問題: -/谷歌地圖2版不加載

logcat的:

06-27 01:21:16.470: I/Google Maps Android API(12628): Google Play services client version: 4452000 
06-27 01:21:16.490: I/Google Maps Android API(12628): Google Play services package version: 4452036 
06-27 01:21:16.790: D/dalvikvm(12628): GC_FOR_ALLOC freed 3003K, 16% free 17823K/21008K, paused 32ms, total 33ms 
06-27 01:21:16.800: I/fpp(12628): Making Creator dynamically 
06-27 01:21:16.800: I/Google Maps Android API(12628): Google Play services client version: 4452000 
06-27 01:21:16.810: W/ActivityThread(12628): ClassLoader.loadClass: The class loader returned by Thread.getContextClassLoader() may fail for processes that host multiple applications. You should explicitly specify a context class loader. For example: Thread.setContextClassLoader(getClass().getClassLoader()); 
06-27 01:21:17.261: I/Google Maps Android API(12628): Failed to contact Google servers. Another attempt will be made when connectivity is established. 
06-27 01:21:24.709: D/dalvikvm(12628): GC_FOR_ALLOC freed 3259K, 15% free 19643K/23084K, paused 40ms, total 40ms 
06-27 01:21:32.367: E/Google Maps Android API(12628): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors). 

Android清單:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    android:versionName="1.0.0" 
    android:versionCode="1" 
    package="com.sahaab.android.muslimzone.test" > 
    <uses-sdk android:minSdkVersion="11" android:targetSdkVersion="19" /> 

    <!-- The following two permissions are not required to use 
    Google Maps Android API v2, but are recommended. --> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/> 
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 

    <!-- Required OpenGL ES 2.0. for Maps V2 --> 
    <uses-feature 
     android:glEsVersion="0x00020000" 
     android:required="true" />  

    <permission 
      android:name="com.sahaab.android.muslimzone.test.permission.MAPS_RECEIVE" 
      android:protectionLevel="signature"/> 

    <uses-permission android:name="com.sahaab.android.muslimzone.test.permission.MAPS_RECEIVE"/> 

    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
    <uses-feature 
     android:name="android.hardware.location" 
     android:required="false" /> 
    <uses-feature 
     android:name="android.hardware.location.network" 
     android:required="false" /> 
    <uses-feature android:name="android.hardware.location.gps" /> 
    <uses-feature 
     android:name="android.hardware.wifi" 
     android:required="false" />  

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
     <meta-data 
      android:name="com.google.android.maps.v2.API_KEY" 
      android:value="AIzaSyDTkYW-kWs9VKB40pv7Qhw972blaz-GD1A" /> 

     <activity 
      android:name="com.sahaab.muslimzone.activity.MainActivity" 
      android:label="@string/app_name" 
      android:launchMode="singleTop" > 
      <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".activities.MyActivity" /> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

     <activity 
      android:name="com.sahaab.muslimzone.activity.InfoActivity" 
      android:label="@string/app_name" 
      android:launchMode="singleTop" > 
      <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".activities.MyActivity" /> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

     <activity 
      android:name="com.sahaab.muslimzone.activity.IqamahActivity" 
      android:label="@string/app_name" 
      android:launchMode="singleTop" > 
      <meta-data android:name="android.support.PARENT_ACTIVITY" android:value=".activities.MyActivity" /> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 

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

    </application> 

</manifest> 

活性:

package com.sahaab.muslimzone.activity; 

import com.sahaab.android.muslimzone.test.R; 

import android.app.Activity; 
import android.os.Bundle; 

public class IqamahActivity extends Activity { 

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

佈局:

<?xml version="1.0" encoding="utf-8"?> 
<fragment xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/iqamah_map" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:name="com.google.android.gms.maps.MapFragment"/> 
+0

@ integer/google_play_services_version的價值是什麼? – justDroid

+0

請檢查我的答案。 –

+0

thnx,對不起我睡着了XD –

回答

2

更新代碼。我希望它可以幫助你。它爲我工作!

package com.sahaab.muslimzone.activity; 

import com.sahaab.android.muslimzone.test.R; 

import android.app.Activity; 
import android.os.Bundle; 

public class IqamahActivity extends FragmentActivity { 

GoogleMap map; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_iqamah); 
map =((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.iqamah_map)).getMap(); 

    } 
} 

更改XML

<?xml version="1.0" encoding="utf-8"?> 
    <fragment xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/iqamah_map" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:name="com.google.android.gms.maps.SupportMapFragment" /> 

有關的更多信息,請訪問:Here

+1

@A使用** MapFragment **有什麼不對? –

+0

@SimplePlan先生:我面臨同樣的問題。然後使用它。實際上,SupportMapFragment屬於v4支持庫,與默認的MagFragment相反,它是Android中的本地組件。 –

+0

如果有什麼錯誤的想法..讓我更多。 –

1

阿米亞·是正確的,你需要使用FragmentActivity使用片段。

要找出Activity和FragmentActivity之間的區別,this可能會有所幫助!

如果您的目標是API 12及以上版本,則可以使用MapFragment。否則,請使用SupportMapFragment。

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 

點擊here查看更多關於Google Maps Android API v2的信息。

希望這會有所幫助!