【问题标题】:Google map does not load at all, without any error谷歌地图根本没有加载,没有任何错误
【发布时间】:2018-12-29 06:31:50
【问题描述】:

Google 地图仍在闪烁且无法加载。所有脚本、api 密钥和代码都是正确的。

应用程序gradle 文件是:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.muzammil.bustracking"
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    implementation 'com.google.android.gms:play-services-location:+'
    implementation 'com.google.android.gms:play-services-maps:+'
    implementation 'com.google.firebase:firebase-core:+'
    implementation 'com.google.firebase:firebase-auth:+'

    //noinspection GradleCompatible
    implementation 'com.google.firebase:firebase-messaging:+'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support:design:26.1.0'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
//    apply plugin: 'com.google.gms.google-services'
}

apply plugin: 'com.google.gms.google-services'

我在实际的 Android 手机上运行应用程序,而不是模拟器。

非常感谢您的回答...

【问题讨论】:

  • 您是否为清单文件添加了权限?
  • 亲爱的,还要避免在库中使用“+”,这是一种不好的做法,请添加正确的版本号。
  • 当然先生,我已经添加了权限。地图现在在模拟器上运行,但在实际手机上它仍然闪烁

标签: android google-maps android-studio google-play-services google-places


【解决方案1】:

我终于找到了解决办法。

实际上,我是在 API 级别 24 的 Android 设备上运行该应用程序,而该应用程序使用的是 API 级别 26。我将目标 SDK 版本从 文件 > 项目结构 > 应用程序 > 口味从 26 更改为 24强>,它起作用了。

感谢大家的帮助!我真的很感激。

【讨论】:

    【解决方案2】:

    我认为您使用了错误的 API 密钥。因此通常不会显示。

    This guide is a quick start to adding a map to an Android app

    【讨论】:

      【解决方案3】:

      试试

      <uses-library android:name="org.apache.http.legacy" android:required="false" />
      

      在清单中让它在应用程序>标签下工作

      【讨论】:

      • 谢谢你先生,它适用于模拟器..但在实际设备中,地图仍然闪烁
      • 也许可以尝试将此添加到您的 onMapReady .setMapType(Google map.MAP_TYPE_NORMAL) 并仔细检查您的 API 密钥
      【解决方案4】:

      确保您在 androidmanifest.xml 中提到了以下权限

      <uses-permission android:name="android.permission.INTERNET" /> 
      

      您的项目中必须有 API 密钥。可以从这个link 获取密钥。 您还必须从GCP itself 启用 API。这需要您机器的 SHA 密钥,可以使用 android studio 生成。

      【讨论】:

      • 所有这些都很好,先生!在调试时,它会将我带到“looper.java”类并显示此消息“字节码与源代码不匹配”
      猜你喜欢
      • 2018-09-14
      • 1970-01-01
      • 1970-01-01
      • 2021-01-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多