1

EDIT 2: It works on an emulator or a real device with Android 10. It doesn't work with a real device on Android 9.

I am developing a Kotlin application on Android Studio 4.0.1 . I need to add a map into this application.

I followed this documentation https://developers.google.com/maps/documentation/android-sdk/start

I generated an API key like it was indicated (I did it multiple times) I added my SHA-1 key for debugging (Also did it several times) I read a LOT of answers on this subject (but it didn't change anything) :

google maps showing blank screen

Google Maps not shown / blank

Google Maps is showing a blank map

I used the Google Maps Activity and also tried to do one by myself. The map never showed up. In any case. I just have a sort of yellow background and the Google logo on bottom left corner of the map.

Here's my manifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ms.easink">
    
    <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"/>

    <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=".application.main.view.MapsActivity"
            android:label="@string/title_activity_maps"/>
        <activity android:name=".application.main.view.MainClientPageActivity" />
        <activity android:name=".application.main.view.MainTattooArtistActivity" />
        <activity android:name=".application.authentication.view.LoginClientSignUpActivity" />
        <activity android:name=".application.authentication.view.LoginTattooArtistSignUpActivity" />
        <activity android:name=".application.authentication.view.LoginSignInActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Could anyone lead me to the right direction help me please?

EDIT: MapsActivity


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_maps)
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        val mapFragment = supportFragmentManager
            .findFragmentById(R.id.map) as SupportMapFragment
        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 fun onMapReady(googleMap: GoogleMap) {
        // Add a marker in Sydney and move the camera
        val sydney = LatLng(-34.0, 151.0)
        googleMap.addMarker(MarkerOptions().position(sydney).title("Marker in Sydney"))
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(sydney))
    }
} 

Screenshot of google console

Maps Sdk enabled

Logcat

Lena
  • 511
  • 1
  • 4
  • 19
  • Make sure you added the maps sdk key , and also enabled the v2 – Taki Jul 17 '20 at 13:00
  • have you debugged your code? your manifest looks fine. Can you post your google maps class which all the map related code is written? – Umair Jul 17 '20 at 13:01
  • @takieddine What do you mean by enabling the V2 ? – Lena Jul 17 '20 at 13:04
  • @Umair Logcat doesn't show anything . When I debug it, my code goes into onMapRead() and my googleMap is not null (it is an instance of SupportMapFragment) – Lena Jul 17 '20 at 13:07
  • Check your logcat for the error that will be generated and please copy paste it here , when there is something wrong with maps sdk , it will throw an error in the logcat – Taki Jul 17 '20 at 13:08
  • @takieddine I've edited my post with the logcat screenshot :) – Lena Jul 17 '20 at 13:10
  • @Lena make sure you have enabled maps api v2 and go through these links, https://stackoverflow.com/questions/35371754/how-to-enable-google-maps-android-api-v2-in-developers-console https://www.tutorialspoint.com/android/android_google_maps.htm https://www.vogella.com/tutorials/AndroidGoogleMaps/article.html I can see there are few things missing in your code, like location services, gms, FusedLocationProviderClient etc and make sure you activity extends implements OnMapReadyCallback, LocationListener – Umair Jul 17 '20 at 13:11
  • @Umair I am going to follow your lead. Why is it not indicated like that in the documentation? – Lena Jul 17 '20 at 13:14
  • @Umair I don't know where to find Maps API V2 . When I write "google maps android api" in the section bar of console.developers.google, it only shows Maps SDK for Android (which is already enabled) and Places API – Lena Jul 17 '20 at 13:28
  • @MartinZeitler It's the layout generated by Google Maps Activity – Lena Jul 17 '20 at 13:32

1 Answers1

0

So... After 48h, I found the solution.

In case it happens to anyone... I had no Wifi or any Internet connection.

Lesson learned !

Lena
  • 511
  • 1
  • 4
  • 19