简体   繁体   中英

Android google maps not showing the actual map

A little bit of context:

Since several weeks ago I'm doing some stuff with google maps api for Android, a week ago I had to reset my PC and after that I cloned my Android project from my private repository. Now, the google maps part of the project won't work, when I start the map activity, it shows the layout as expected but the map is not rendered, I only see the Google logo at the bottom left corner.

I have checked the following:

  • I have got a developer console API KEY of the form AIzaSyA*****************
  • The API KEY credentials are for the package co.com.something.activities and the SHA1 certificate given by the auto-generated google_maps_api.xml which says

    You can also add your credentials to an existing key, using this line: D6:76:DA:B5:##:##:##:##:##:##:##:##:##:##:##:##:##;co.com.something.activities

  • I have in my manifest

      <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_COARSE_LOCATION" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-feature android:glEsVersion="0x00020000" android:required="true" /> <meta-data android:name="com.google.android.geo.API_KEY" android:value="@string/google_maps_key" /> <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> 

  • The API KEY on google_maps_api.xml is the same as the console API KEY

  • The onMapReady(GoogleMap googleMap) method is getting called on my activity and I'm setting some LatLng points and moving the camera (still won't show the map)

  • I've tried the following actions from Android Studio: Build APK, Generate Signed APK, then uploaded those apks to my phone (None worked).

  • I have my keystore for release under the app's project folder, I have deleted it and created it and recreated the API KEY with the new SHA1

  • I haven't touched the debug.keystore as I'm not aware where it is located.

  • I'm loading the map into a fragment from an activity (it worked fine)

 <fragment 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="fill_parent" android:id="@+id/map" tools:context="co.com.wayfit.activities.RouteActivity" android:name="com.google.android.gms.maps.SupportMapFragment" /> 

And this is my gradle file

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
signingConfigs {
    release {
        storeFile file('C:/ProjectDir/app/wayfit.keystore')
        storePassword "wayfit"
        keyAlias "wayfit"
        keyPassword "wayfit"
    }
}
defaultConfig {
    applicationId "co.com.wayfit"
    minSdkVersion 15
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    signingConfig signingConfigs.release
}

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.release
    }
}
productFlavors {
}
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.android.support:design:23.1.1'
    compile 'com.google.android.gms:play-services:8.3.0'
    compile 'com.google.android.gms:play-services-ads:8.3.0'
    compile 'com.google.android.gms:play-services-identity:8.3.0'
    compile 'com.google.android.gms:play-services-gcm:8.3.0'
}

EDIT:

I think my problem is due to the API KEY. I tried deleting the activity and creating a new map activity, android studio generated a file for me named google_maps_api.xml and it said You can also add your credentials to an existing key, using this line: D6:76:DA:B5:##:##:##:##:##:##:##:##:##:##:##:##:##;co.com.something.activities

so I thought to use that for my api credentials, however when I run the command prompt "keytool -v -list -keystore mykeystore.keystore" which is the same I'm using to sign the apk, I'm receiving another different SHA1

D8:B2:29:2C:C5:##:##:##:##:##:##:##:##

I used both in the same API KEY under the same packages on the developers console.

Another thing that bugs me is google_maps_api.xml says (debug) at the right side of the name, does this influence something?

  • Check if your devices' date & time settings correspond to your current time zone (Unfortunately the log output will not return much constructive information to lead you to think about the date & time)
  • Check if you've enabled the correct service in your API console (Enable Google Maps API Android V2 not Google Maps API V2, log will return Authentication Failed if you do something wrong with this step)
  • Check if you've used the correct keystore to get the API secret (The log will give you a hint saying Authentication Failed
  • Check if you've included the correct library files

More info can be found in tons of others questions regarding blank google maps: https://stackoverflow.com/a/15636254/1099716

The API_KEY for debug was stored app\\src\\debug\\res\\values\\google_maps_api.xml

Putting the API_KEY for release to google_maps_api.xml file by the folder app\\src\\release\\res\\values works for me as mentioned this answer..

https://stackoverflow.com/a/42123330/2796625

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM