Google Maps blank on real Android device - but wor

2019-07-15 02:24发布

问题:


Hola,

I am trying to get the maps to work, it appears to work fine the the Nexus 6 emulator, however when I run it on a Moto G or a Samsung Galaxy the map is completely bank - it just contains the google logo in the bottom corner.

I have generated a google maps key and put that in my google_maps_api.xml file. Do I have to generate a SHA-1 certificate fingerprint? If yes, how do I do this?

See answer: https://stackoverflow.com/a/33691443/5387193 I don't quite understand the instructions.

Here is my log: http://textuploader.com/52xzy

Edit 1: Added line to AndroidManifest.xml

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

It is now working on my Moto G but not on my Samsung. I think because I haven't accepted the sensitive information permission (ACCESS_FINE_LOCATION).

This app I am working on does not need to know the GPS location of the user, so I don't really need this sensitive information - is there an easy way to remove this function and permission?

I think the permission is causing the problems.

Edit 2: I have got the code:

<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/google_maps_key" />

in my AndroidManifest.xml, the @string/google_maps_key is a correct key that I have generated. I have generated a SHA1 fingerprint to get the key, do I need to put the fingerprint in my code somewhere?

I haven't generated a release key, I think it is just a debug key. Do you think this might be the issue?

I will setup google play services and see how that affects it.

Edit #3: Uninstalled and reinstalled Google Play Services on Samsung and now it is working.

回答1:

This line in your logcat seems to be the problems:

02-23 10:02:01.591 5760-5760/com.companyperth.companytools E/GMPM: GoogleService failed to initialize, status: 10, Missing an expected resource: 'R.string.google_app_id' for initializing Google services.  Possible causes are missing google-services.json or com.google.gms.google-services gradle plugin.

It looks like Google Play services is not properly setup. You need to get google-services.json and put it into your project. To set up Google Play Services correctly, see Google APIs for Android.

You need to generate SHA1 fingerprint in order to get the Android key if you are using Google Maps for Android. See Get API key - Google Maps for Android. However, if you are using the Google Maps Javascript API(integrated into Android) you will not need to generate SHA1 fingerprint as you will be using Server Key.



回答2:

Try to update your google map. I think that is the issue.