Rad
Rad

Reputation: 57

google maps white screen

I'm trying to implement google maps into my application, I have implemented a register and login activities after user logs in, but I want to display a map and it shows up as a blank screen. I have generated the API key and added it into my google_maps_api.xml

When I create a new project and add map activity to it then it works without any problem, I think that they problem is somewhere in my project.

I have tested it on emulator as well as Samsung device.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.x.x.x">

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

<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_PROFILE"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
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-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
    <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key"/>

    <activity
            android:name=".Activitys.MainActivity"
            android:screenOrientation="portrait">
    </activity>
    <activity
            android:name=".Activitys.Register"
            android:screenOrientation="portrait">
    </activity>
    <activity
            android:name=".Activitys.Register2"
            android:screenOrientation="portrait">
        android:noHistory="true"
    </activity>
    <activity
            android:name=".Activitys.Login"
            android:screenOrientation="portrait">
    </activity>
    <activity android:name=".Activitys.Family_setup">
    </activity>
    <activity android:name=".Activitys.Join_family">
    </activity>
    <activity android:name=".Activitys.Create_family">
    </activity>
    <!--
         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/. 
    -->

    <activity
            android:name=".Activitys.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>

For the testing purposes I have settled the map activity to start first.

When I run the application I get a white screen with google's logo in bottom left corner.

image

Upvotes: 0

Views: 3260

Answers (3)

xaif
xaif

Reputation: 563

After suffering 2 days with this error , I found a really good solution .

Actually , I debug app by installing release signed apk on emulator and check Logcat which is showing :

E/Google Maps Android API﹕ Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
E/Google Maps Android API﹕ In the Google Developer Console (https://console.developers.google.com)
Ensure that the "Google Maps Android API v2" is enabled.
Ensure that the following Android Key exists:
API Key: YOUR_KEY_HEREAndroid Application (<cert_fingerprint>;<package_name>): 
<SHA1 Removed for this> ;com.xaif.mapstest

This is because your app has different SHA-1 fingerprint for release version . So , generate a new SHA-1 fingerprint for released version and add it to Restriction section in Credentials with same package name. This takes 5-10 minutes to add . Now , Your app runs perfectly.

Upvotes: 1

Daniel Eberl
Daniel Eberl

Reputation: 1424

I had the same issue aswell, and just wanted to say thank you for sharing your solition. I also wanted to add something:

1) You can edit the packagename in your Developer Console at google aswell, so you dont need to rename packages and dependencies in your app. You can aswell provide your root package name and do not have to limit a key to one activity

2) Debugging on my Phone via USB worked well, while the Simulator still doesn‘t render the map

3) You will need a different API Key for your release Version of your App, since the API Key is bound to SHA1 of your apk, which is different from debug to release mode. There are actually 2 seperate files/directories in your res folder.

Upvotes: 1

Rad
Rad

Reputation: 57

Thank you for help.

I have changed the activity name from android:name=".Activitys.MapsActivity" to android:name="com.project.me.appname.Activitys.MapsActivity" this has solved the problem for me.

Upvotes: 1

Related Questions