尽管使用Android Kotlin创建Android应用程序,即使该应用程序正常运行,也无法显示地图

问题描述 投票:0回答:1

尽管使用Android Kotlin创建Android应用程序时,即使该应用程序正常运行,也无法显示地图,但该地图为空白,其中没有任何内容。

也尝试通过更改Api键

package com.example.currentlocationexample

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 MapsActivity : AppCompatActivity(), OnMapReadyCallback {

    private lateinit var mMap: GoogleMap

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

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

创建地图活动后自动开发的代码,但是在AVD上运行后不会显示地图。

android kotlin location maps
1个回答
0
投票
2020-05-29 11:23:31.148 212-212/? I/hwservicemanager: getTransport: Cannot find entry [email protected]::IAllocator/default in either framework or device manifest.
2020-05-29 11:23:31.156 8721-8791/com.example.currentlocationexample E/Google Maps Android API: In the Google Developer Console (https://console.developers.google.com)
    Ensure that the "Google Maps Android API v2" is enabled.
    Ensure that the following Android Key exists:
        API Key: AIzaSyAUhYTWyk24s2_73aD4BlvIuP_4UZP
        Android Application (<cert_fingerprint>;<package_name>): 73:E8:C1:5C:01:85:AF:F5:58:D1:28:B5:4E:E8:B8:08:18:F0:24:9C;com.example.currentlocationexample```
© www.soinside.com 2019 - 2024. All rights reserved.