我正在將Google地圖整合到一個小應用程序中。我AndroidManifest.xml
是Google地圖加載問題
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mymaps"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.mymaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission
android:name="info.androidhive.googlemapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<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"/>
<uses-feature 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.example.mymaps.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="MyKey" />
</application>
</manifest>
而我的主要活動是
public class MainActivity extends Activity implements OnClickListener {
TextView lat,lng;
Button getCds,getMap;
private GoogleMap googleMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initializeVars();
}
private void initializeVars() {
// TODO Auto-generated method stub
getCds = (Button)findViewById(R.id.bGC);
getMap = (Button)findViewById(R.id.bGM);
lat = (TextView)findViewById(R.id.TextView2);
lng = (TextView)findViewById(R.id.TextView4);
getCds.setOnClickListener(this);
getMap.setOnClickListener(this);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
@Override
protected void onResume() {
super.onResume();
initilizeMap();
}
public void onClick(View v) {
Log.d("Debugging", "I am in onCLick");
switch (v.getId()) {
case R.id.bGC:
{
Log.d("Debugging", "I am in case R.id.bGC");
lat.setText("My Lat");
lng.setText("My Long");
break;
}
case R.id.bGM:
{
Log.d("Debugging", "I am in case R.id.bGM");
lat.setText("blank");
lng.setText("blank");
break;
}
}
}
}
當我加載我提示以下錯誤:應用程序。
01-17 14:01:49.054: E/Google Maps Android API(2832): Authorization failure. Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
01-17 14:01:49.064: E/Google Maps Android API(2832): Ensure that the following correspond to what is in the API Console: Package Name: com.example.mymaps, API Key: MyKey, Certificate Fingerprint: SomeValue
01-17 14:01:49.064: I/Google Maps Android API(2832): Failed to contact Google servers. Another attempt will be made when connectivity is established.
01-17 14:01:59.234: D/dalvikvm(2832): GC_CONCURRENT freed 572K, 9% free 7576K/8263K, paused 6ms+3ms
01-17 14:02:04.304: E/Google Maps Android API(2832): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
夥計們給一點更多的視角。用於之前工作的相同代碼(可能是3-4個月前)。它似乎不再有效。我不確定是什麼原因導致相同。
你可以請指教如何調試一樣嗎?
你不需要'permission.MAPS_RECEIVE'。 Google Play Services 3.1.59使其無效。資料來源:http://stackoverflow.com/questions/14832911/android-map-v2-why-maps-receive-permission – gian1200
您使用的是Google Play服務的哪個版本? – gian1200
我在哪裏檢查?對不起,我是新的,所以不知道在哪裏檢查相同。 – misguided