Home>
I want to use Google Maps activity in Android studio

I'm trying to use the Google Maps activity in android studio.
However, when I try to do the same while looking at the following sites, the map is not displayed in the emulator.

■ Referenced site
https://akira-watson.com/android/google-maps-api-v2.html

■ Current display status
  

■ Work performed

  1. Get the API key from the link in google_maps_api.xml
  2. Copy API key
  3. Set beforein google_maps_api.xml

Since it is not displayed, I repeated the same operation several times, but it is not displayed.
Currently, I have deleted unnecessary projects that have been created through repeated work, leaving only the API projects that are installed.

Applicable source code

google_maps_api.xml

   <string name = "google_maps_key" templateMergeStrategy = "preserve" translatable = "false">API key is put here</string>


AndroidManifest.xml

<? xml version = "1.0" encoding = "utf-8"?><manifest xmlns: android = "http://schemas.android.com/apk/res/android"
    package = "Package name was included">    <!-
         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" />            <!-
             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 /.
        ->        <meta-data
            android: name = "com.google.android.geo.API_KEY"
            android: value = "@ string/google_maps_key" />        </activity>                            <intent-filter>                                <category android: name = "android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application></manifest>


Activity_map.kt

package package name was included
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.MarkerOptions
class Activity_map: AppCompatActivity (), OnMapReadyCallback {
    private lateinit var mMap: GoogleMap
    override fun onCreate (savedInstanceState: Bundle?) {
        super.onCreate (savedInstanceState)
        setContentView (R.layout.activity_map)
        // 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) {
        mMap = googleMap
        // Add a marker in Sydney and move the camera
        val sydney = LatLng (-34.0, 151.0)
        mMap.addMarker (MarkerOptions (). position (sydney) .title ("Marker in Sydney"))
        mMap.moveCamera (CameraUpdateFactory.newLatLng (sydney))
    }
}


Activity_map.xml

<? xml version = "1.0" encoding = "utf-8"?><fragment 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: id = "@ + id/map"
    android: name = "com.google.android.gms.maps.SupportMapFragment"
    android: layout_width = "match_parent"
    android: layout_height = "match_parent"
    tools: context = ". Activity_map" />
What I tried

Check if google play service is installed
Make sure that the API key, package name, and SHA-1 signature certificate fingerprint are correct (I'm worried because I don't understand the Google platform).
Check if there are any errors in the logcat and debug fields (I did not see any errors, but I'm a beginner so I'm worried that the usage is wrong)

Supplemental information (FW/tool version, etc.)

Language uses Kotlin