【发布时间】:2018-01-13 16:52:05
【问题描述】:
我正在尝试在我的应用程序中实现谷歌地图,我在用户登录后实现了注册和登录活动,但我想显示一个地图,它显示为一个空白屏幕。 我已生成 API 密钥并将其添加到我的 google_maps_api.xml
当我创建一个新项目并向其添加地图活动时,它可以正常工作,我认为他们的问题出在我的项目中。
我已经在模拟器和三星设备上测试过了。
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.x.x.x">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!-- To auto-complete the email text field in the login form with the user's emails -->
<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.READ_PROFILE"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<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=".Activitys.MainActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".Activitys.Register"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".Activitys.Register2"
android:screenOrientation="portrait">
android:noHistory="true"
</activity>
<activity
android:name=".Activitys.Login"
android:screenOrientation="portrait">
</activity>
<activity android:name=".Activitys.Family_setup">
</activity>
<activity android:name=".Activitys.Join_family">
</activity>
<activity android:name=".Activitys.Create_family">
</activity>
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<activity
android:name=".Activitys.MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
出于测试目的,我已将地图活动设置为首先开始。
当我运行应用程序时,我得到一个白屏,左下角有谷歌的标志。
【问题讨论】:
-
Google 地图需要 API 密钥才能工作,developers.google.com/maps/documentation/android-api/signup
-
我已经添加了API密钥,但它仍然只显示白屏。
-
检查您的日志是否有错误
-
错误是授权失败,虽然我确定我使用了正确的 API 密钥。
-
同时发布错误消息并仔细检查 API 密钥是否有正确的限制。
标签: android google-maps screen