1

编辑 2:它适用于模拟器或带有 Android 10 的真实设备。它不适用于 Android 9 上的真实设备。

我正在 Android Studio 4.0.1 上开发 Kotlin 应用程序。我需要在这个应用程序中添加一个地图。

我遵循了这个文档https://developers.google.com/maps/documentation/android-sdk/start

我生成了一个 API 密钥,就像它指示的那样(我做了多次)我添加了我的 SHA-1 密钥进行调试(也做了几次)我阅读了很多关于这个主题的答案(但它没有改变任何东西) :

谷歌地图显示黑屏

谷歌地图未显示/空白

谷歌地图显示空白地图

我使用了谷歌地图活动,也尝试自己做一个。地图从未出现过。任何状况之下。我只有一种黄色背景和地图左下角的谷歌标志。

这是我的清单:

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

任何人都可以引导我走向正确的方向吗?

编辑:地图活动


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

谷歌控制台截图

地图 SDK 已启用

日志猫

4

1 回答 1

0

所以...... 48小时后,我找到了解决方案。

万一发生在任何人身上……我没有 Wifi 或任何互联网连接。

学过的知识 !

于 2020-07-19T12:30:49.083 回答