Android Maps: Failed to load map. Failed to contact Google servers.

This mistake was permanent forever. (I made sure "Google Maps Android API v2" is enabled.)

Here is MainActivity.java:

package com.example.maptest; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.view.Menu; public class MainActivity extends FragmentActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } } 

manifest:

  <uses-sdk android:minSdkVersion="17" android:targetSdkVersion="17" /> <permission android:name="com.example.maptest.permission.MAPS_RECEIVE" android:protectionLevel="signature" /> <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> <uses-permission android:name="com.example.maptest.permission.MAPS_RECEIVE" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-feature android:name="android.hardware.location" android:required="true" /> <uses-feature android:name="android.hardware.location.network" android:required="true" /> <uses-feature android:name="android.hardware.location.gps" /> <uses-feature android:name="android.hardware.wifi" android:required="true" /> <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" > <uses-library android:name="com.google.android.maps" /> <activity android:name="com.example.maptest.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="AIzaSyAoDwhSzOopQ3g8NBe7d0WblR72TkmnVPU" /> </application> </manifest> 

activity_main.xml:

 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:map="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <fragment class="com.google.android.gms.maps.SupportMapFragment" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.MapFragment"/> </RelativeLayout> 

Please, help! I'm not sure what went wrong ... although I ended up following / combining various textbooks because none of them worked on its own.

+6
source share
1 answer

1. The first problem that I see here:

 <fragment class="com.google.android.gms.maps.SupportMapFragment" android:id="@+id/map" android:layout_width="match_parent" android:layout_height="match_parent" android:name="com.google.android.gms.maps.MapFragment"/> 

delete this line: class = "com.google.android.gms.maps.SupportMapFragment"

and set android:name as:

  android:name="com.google.android.gms.maps.SupportMapFragment" 

2. Remove this line from the manifest file:

 <uses-library android:name="com.google.android.maps" /> 

This permission is Google Maps API V1 and should not be used in API V2 .

Take a look at this blog post and make sure everything is correct:

Google Maps V2 API

3. The problem you are describing is usually due to a problem when creating or registering an API key using the API console. If you are sure that all the steps were performed correctly, I suggest you delete the debug.keystore folder, compile some project in Eclipse (this will result in a new SHA1 key) and register the key again using the console. Take a look at this blog post that I wrote and make sure that I am doing all the steps correctly:

Google V2 Map API Key

+6
source

Source: https://habr.com/ru/post/943799/


All Articles