Hello! I am trying to launch a google maps application on my device, which is connected via usb to a computer, and I bring the result to it. The fact is that when I launch the google maps application, only a beige rectangle and the google logo are displayed on the bottom left. I created the Google Maps Activity, got the API key, inserted it into the manifest. I do not understand the reason. They wrote that the problem may be that the API key is incorrect. Then how to do right?

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.nikiz.myapplicationmaps"> <!-- The ACCESS_COARSE/FINE_LOCATION permissions are not required to use Google Maps Android API v2, but you must specify either coarse or fine location permissions for the 'MyLocation' functionality. --> <uses-feature android:glEsVersion="0x00020000" android:required="true"/> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:name="android.support.multidex.MultiDexApplication" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <!-- The API key for Google Maps-based APIs is defined as a string resource. (See the file "res/values/google_maps_api.xml"). Note that the API key is linked to the encryption key used to sign the APK. You need a different API key for each encryption key, including the release key that is used to sign the APK for publishing. You can define the keys for the debug and release targets in src/debug/ and src/release/. --> <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" /> <activity android:name=".MapsActivity" android:label="@string/title_activity_maps"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> 

Gradle:

 apply plugin: 'com.android.application' android { compileSdkVersion 24 buildToolsVersion "22.0.1" defaultConfig { applicationId "com.example.nikiz.myapplicationmaps" minSdkVersion 19 targetSdkVersion 24 multiDexEnabled true versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:24.2.1' compile 'com.google.android.gms:play-services:9.8.0' compile 'com.android.support:multidex:1.0.1' testCompile 'junit:junit:4.12' } 

MapsActivity.java:

 package com.example.nikiz.myapplicationmaps; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import com.google.android.gms.maps.CameraUpdateFactory; import com.google.android.gms.maps.GoogleMap; import com.google.android.gms.maps.OnMapReadyCallback; import com.google.android.gms.maps.SupportMapFragment; import com.google.android.gms.maps.model.LatLng; import com.google.android.gms.maps.model.MarkerOptions; public class MapsActivity extends FragmentActivity implements OnMapReadyCallback { private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); } /** * Manipulates the map once available. * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; // Add a marker in Sydney and move the camera LatLng sydney = new LatLng(-34, 151); mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney")); mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); } } 
  • There should be logs when entering activations with mapa and there is something that should clarify the situation - JVic
  • The Error filter found the following: /com.example.nikiz.myapplicationmaps E/b: Authentication failed. Timeout while trying to contact the server. /com.example.nikiz.myapplicationmaps E/b: Authentication failed. Timeout while trying to contact the server. - NikiZ
  • Is the key active in the developer console? - JVic

2 answers 2

The manifest seems to have forgotten permissions for accessing the network. This is a cloud service, it needs to go to the cloud for the card itself.

 <uses-permission android:name="android.permission.INTERNET"/> 
  • Unfortunately it did not help. In addition, the documentation read that this permission is automatically added, it is not necessary to specify it explicitly. - NikiZ
  • I automatically read about, thank you, I wonder even. I forgot it the other day and then added it. look then in the logs, there should be a hint. check that the key is fresh, that the application id matches. - tse
  • You were right, it seems, it was necessary to add exactly this permission. I have very little experience, so I did not know that I needed to remove the application from the device before outputting the result to it again, so yesterday I didn’t display anything. Thank! - NikiZ

Try to set all the same permissions:

 <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 

Also as a pleasant remark, it is not worth importing the entire library.

  compile 'com.google.android.gms:play-services:9.8.0' 

So that is why I think you had to finish multidex.

Well, for the sake of trial, try adding a marker as follows:

 public void onMapReady(GoogleMap map) { LatLngBounds.Builder builder = new LatLngBounds.Builder(); Marker marker = map.addMarker(new MarkerOptions() .position(new LatLng(47.045029, 28.861427)) .title("Marker")); builder.include(marker.getPosition()); LatLngBounds bounds = builder.build(); int padding = 150; CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, padding); map.moveCamera(cu); } 

I hope the answer will be useful.

UPD

To bypass the mulitdex import, it is advisable to import the maps in the following way (if of course you are going to use only maps):

 compile 'com.google.android.gms:play-services-maps:9.8.0' compile 'com.google.android.gms:play-services-location:9.8.0' 

Instead

  compile 'com.google.android.gms:play-services:9.8.0' 
  • Thanks for the answer! Please tell me how I can not import the entire library, so how did I have to do multidex because of it? - NikiZ
  • Updated the answer. You can read. - Morozov
  • Thank you very much, you really helped! - NikiZ