如何在模拟器上显示地图

从Android Studio开始,我创建了一个Map Activity项目; 所以,没有自定义代码。

唯一的自定义更改是复制google_maps_api.xml _( https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=) _中的url,并使用它创建API密钥。

Android Studio:3.0.1模拟器:带API 25的Nexus 5X

Build.gradle文件


应用插件:'com.android.application'

应用插件:'kotlin-android'

应用插件:'kotlin-android-extensions'

 android {
     compileSdkVersion 26
     defaultConfig {
         applicationId“xxxx.xxx.xxxx”
         minSdkVersion 19
         targetSdkVersion 26
         versionCode 1
         versionName“1.0”
         testInstrumentationRunner“android.support.test.runner.AndroidJUnitRunner”
     }
     buildTypes {
        发布 {
             minifyEnabled false
             proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
         }
     }
 }

依赖{
    执行fileTree(dir:'libs',include:['* .jar'])
    实施 “org.jetbrains.kotlin:科特林-STDLIB-jre7:$ kotlin_version”
    实现'com.android.support:appcompat-v7:26.1.0'
    实现'com.google.android.gms:play-services-maps:11.0.0'
     testImplementation'junit:junit:4.12'
     androidTestImplementation'com.android.support.test:runner:1.0.1'
     androidTestImplementation'com.android.support.test.espresso:espresso-core:3.0.1'
 }

截图

在这里输入图像说明

我好像错过了一些东西; 我只是不知道它是什么。

尝试在你的手机上运行。 有时模拟器无法正确加载地图,这就是为什么它显示空白的地图没有加载根。