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 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))
}
}