本文介绍了为什么Google Maps在我的Android应用程序中显示空白屏幕?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Android应用中有Google Maps.我是通过选择新的Google Maps Activity&添加它的将密钥粘贴到Android Studio中.在我的Android手机(Lenovo K5 Note)中,它工作正常,但是当我将项目复制到另一台计算机上时,在另一台设备(Coolpad)中运行时,它会在左下角显示一个空白屏幕(米色或白色),并带有Google徽标.

I have Google Maps in my Android App. I added it by selecting new Google Maps Activity & pasting the key in Android Studio. It worked fine in my Android phone (Lenovo K5 Note) but when I copied the project to another computer & run in another device (Coolpad), it shows a blank screen (beige or white colored) with Google logo on bottom left.

推荐答案

过去两天与空白地图作战,这是从各种来源收集的摘要(我确定这不是可能出现问题的完整列表!).

Fought with blank map past two days and here is the summary (which I'm sure is not a complete list of possible issues!) collected from various sources.

似乎是最常见的.我建议遵循官方文档.如果完成所有步骤,问题仍然存在,并且您仍然不确定是否可能是原因,请克隆官方android示例,找到MapWithMarker示例(android-samples/tutorials/MapWithMarker)并对其进行测试.如果您运行示例并正确显示了地图,请尝试将默认的API KEY交换为您拥有的API KEY.

Seems to be most often. I recommend to follow official documentation. If you finish all steps, issue persists and you're still unsure whether it could be the reason, clone official android samples, find the MapWithMarker sample (android-samples/tutorials/MapWithMarker) and test against it. If you run the sample and it shows the map correctly, try to exchange default API KEY for the one you own.

  • 如果有效,则密钥不是问题.
  • 如果它不起作用,关键是您的问题.

请确保在这种情况下,您已在 Google API控制台中启用了该功能.

In such case make sure, you enabled it in Google API Console.

您的AndroidManifest.xml需要定义以下元数据属性:

Your AndroidManifest.xml needs to define following metadata attribute:

<meta-data android:name="com.google.android.gms.version"
      android:value="@integer/google_play_services_version" />

有关更多详细信息,请参见此处的答案官方文档.

See the answer here for more details and official documentation.

在旧版的Android SDK中,您必须明确设置某些用户权限才能正确使用Google Maps API,例如:

In older versions of Android SDK, you had to explicitly set certain user permissions to work with Google Maps API correctly, for example:

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

情况不再如此,但我建议您访问官方文档以确保您符合这些版本要求.

This is not the case anymore but I would recommend to visit official documentation to make sure you meet those version requirements.

过去,似乎需要在AndroidManifest.xml中指定以下元数据属性

In the past, there seemed to be requirement to specify following metadata attribute within AndroidManifest.xml

<uses-feature
   android:glEsVersion="0x00020000"
   android:required="true"/>

官方文档 .一些其他详细信息可用,例如此处.

This shouldn't be required anymore per official documentation. Some additional details are available e.g. here.

Android Studio 3.0 AVD Manager允许您为似乎不太正常的API创建设备配置.目前,您可以针对API v27创建配置,如果我没记错的话,该配置似乎尚未发布.直到我开始使用Google Maps API之前,基本的模拟效果都很好.设置为v27的设备配置均无法与Maps API配合使用,从而导致空白地图.

Android Studio 3.0 AVD Manager allows you to create device configurations for APIs that don't seem to be working well. At the moment, you can create configuration against API v27 which doesn't seem to be released yet if I'm not mistaken. Basic emulations worked well even there until I started work with Google Maps API. None of the device configurations set to v27 worked with Maps API resulting in blank map.

  • 尝试降级以降低SDK版本.

注意:如果有更深的知识的人纠正我的简化且可能不正确的解释,将感到高兴.由于这是我的问题,因此我不再进行更深入的评估,而只是暂时切换到其他配置.

使用以下设置:

Android Studio 3.0
Build #AI-171.4408382, built on October 20, 2017
JRE: 1.8.0_152-release-915-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0

希望这将帮助至少一个人节省一些时间..

Hope this will help at least one person to save some time..

这篇关于为什么Google Maps在我的Android应用程序中显示空白屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 17:39