user2387273
user2387273

Reputation: 41

Map Fragment not working in Android

I've already tried a thousand configurations and codes, but my map activity insists in not working. Things I've tried:

AndroidManifest.xml

build.gradle

Code

activity_map.xml:

    <fragment android:id="@+id/activityMapID"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

Others

In first call, I have this log:

    03-21 09:34:28.478 25570-26174/com.myapp I/LoadedApk: connected(), package name=com.google.android.gms ,class name=com.google.android.gms.maps.auth.ApiTokenService
    03-21 09:34:29.770 25570-25570/com.myapp I/Choreographer: Skipped 127 frames!  The application may be doing too much work on its main thread.
    03-21 09:34:30.020 25570-27391/com.myapp I/b: Sending API token request.
    03-21 09:34:30.090 25570-25633/com.myapp I/LoadedApk: connected(), package name=com.google.android.gms ,class name=com.google.android.location.internal.GoogleLocationManagerService
    03-21 09:34:31.231 25570-27391/com.myapp I/b: Received API Token: AH0uPGGIx9Ygap4ZXq8T8vK7qcPxgyDi5NRIaIPyPauG4xWFn1lI7KQF9IuY2yqbpYMhWitKnTUiU-sZD9tFdJvr1naCVhz3c9APmLbueopuhcD6K5LHpZKnkYCQDEefhrTeGPNOR0fdz0QmC4WD8rkgQTbLmfbnOIA7cvZZBOmn7hFmcyavIVRQZlaY9_OLaPMFxIVFVBml / Expires in: 432000000ms
    03-21 09:34:31.241 25570-27391/com.myapp I/c: Scheduling next attempt in 431700 seconds.
    03-21 09:34:31.251 25570-27391/com.myapp I/d: Saved auth token
    03-21 09:34:31.832 25570-25582/com.myapp I/LoadedApk: connected(), package name=com.google.android.gms ,class name=com.google.android.gms.clearcut.service.ClearcutLoggerService

Then after second call, I have the message that my key is invalid:

    03-21 09:35:22.596 25570-25633/com.myapp I/LoadedApk: connected(), package name=com.google.android.gms ,class name=com.google.android.gms.clearcut.service.ClearcutLoggerService
    03-21 09:35:37.762 25570-25570/com.myapp I/Google Maps Android API: Google Play services package version: 8703034
    03-21 09:35:37.973 25570-28472/com.myapp E/Google Maps Android API: Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).
    03-21 09:35:38.363 25570-25582/com.myapp I/LoadedApk: connected(), package name=com.google.android.gms ,class name=com.google.android.location.internal.GoogleLocationManagerService

I really don't know what to do anymore. Does someone have any idea what could be happening?

Thanks in advance.

Upvotes: 2

Views: 2404

Answers (2)

user2387273
user2387273

Reputation: 41

Finally I found the problem.

In another part of my code, I was calling

    HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());

To simplify all the calls I do for HTTPS. The issue was when Google Maps tried to call its server: it was using the same SSL Context I've set before so it couldn't connect on Map servers.

I've just commented that line and changed my code to:

    URLConnection urlConn = new URL(myAddress).openConnection();
    HttpsURLConnection https = (HttpsURLConnection) urlConn;
    https.setSSLSocketFactory(sslContext.getSocketFactory());

and everything worked like magic!

Thanks everyone!

Upvotes: 1

Shailendra Madda
Shailendra Madda

Reputation: 21561

Try to add this line at the end of the build.radle

apply plugin: 'com.google.gms.google-services'

Add it in inside of manifest tag :

<uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" >
    </uses-feature>

Upvotes: 0

Related Questions