谷歌地图无法加载并显示空白屏幕 尝试了一些指南,并尝试了谷歌的指南,但似乎都没有 这是我添加的所有内容,无法找到问题: - /
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 manifest:
<?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 :(得分: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" />
For,更多信息请访问Here
答案 1 :(得分:1)
Amiya是对的,你需要使用FragmentActivity来使用碎片。
要了解Activity和FragmentActivity之间的区别,this可能有所帮助!
如果您要定位API 12及更高版本,则可以使用MapFragment。否则,请使用SupportMapFragment。
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
点击here查看有关Google Maps Android API v2的更多信息。
希望这有帮助!