提问者:小点点

Google Maps为空白/空


编辑2:它可以在模拟器或Android10的真实设备上工作。 它在Android9上的真实设备上并不起作用。

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

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

我像指示的那样生成了一个API键(我做了多次),我添加了我的SHA-1键用于调试(也做了多次),我阅读了很多关于这个主题的答案(但它没有改变任何事情):

谷歌地图显示空白屏幕

Google地图未显示/空白

Google Maps显示一张空白地图

我使用了谷歌地图activity,也试着自己做了一个。 地图一直没出现。 无论如何。 我只是有一种黄色的背景和谷歌标志在左下角的地图。

这是我的清单:

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

有谁能帮我指引正确的方向吗?

编辑: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))
    }
} 


共1个答案

匿名用户

如果您正在使用模拟器,请安装google play服务