这个问题很常见但是我没有在google或stackoverflow上找到解决方案(4天的研究......)
以下是:
我需要显示一个全屏谷歌地图,我已经在我开发的其他应用程序中已经多次完成了。 但是在这里,我不能让它为一个不明原因而工作!
当我打开包含地图的SherlockFragmentActivity时出现的警告和错误:
The Google Play services resources were not found. Check your project configuration to ensure that the resources are included.
Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
在这里,我将解释我如何详细处理并发布一些代码:
图书馆导入:
在eclipse中导入的最新版本的Google Play服务作为库(已选中) 在该项目中,Google Play服务作为库导入属性(如ABS)
清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="pck name"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<permission
android:name="com.company.pckgname.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<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_NETWORK_STATE" />
<!-- LOCATION -->
<uses-permission android:name="android.permission.ACCESS_GPS" />
<uses-permission android:name="android.permission.ACCESS_ASSISTED_GPS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:name="app variable name"
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/Theme.Styleapp" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="api key" />
<activity
android:name=".ActivityLauncher"
android:configChanges="orientation|screenSize"
android:label="@string/app_name"
android:screenOrientation="portrait"
android:theme="@style/Theme.Sherlock.NoActionBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
... activities...
</application>
</manifest>
地图布局:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.company.pckgname.TransparentSupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
活动:
public class ActivityGoogleMap extends SherlockFragmentActivity implements OnInfoWindowClickListener {
GoogleMap _googleMap;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// ABS
ActionBar bar = getSupportActionBar();
bar.setTitle(R.string.tle_map);
bar.setDisplayHomeAsUpEnabled(true);
// MAP
_googleMap = ((TransparentSupportMapFragment) getSupportFragmentManager().findFragmentById((R.id.map))).getMap();
//the map should still display at this point
}
}
就是这样,主要代码在这里
到目前为止,地图一直在运行,我没有与代码地图相关...
我尝试在google控制台上重新生成一个调试密钥,更改权限..等我不在乎!!!!
答案 0 :(得分:1)
更改AndroidManifest.xml
中的API密钥后,必须清除应用程序数据。
要清除应用程序数据,请执行以下操作之一:
Settings > Application Manager > Select Your Application > Clear Data
答案 1 :(得分:0)
<uses-feature android:glEsVersion="131072" android:required="true" />
将此权限置于您的清单中。