我尝试过并试图解决这个问题。我到处搜索,我还没有找到解决方案。我知道有很多关于这个主题的论坛,但没有一个能帮我提出解决方案。
我遇到的问题是,当我运行我的Android应用程序时,在模拟器中,地图区域仅出现灰色图块。我在网上看到问题很可能是谷歌API密钥,但我已经尝试了多种方式来生成它(使用Android Studio终端获取SHA1,我有Android工作室生成链接谷歌所以它可以自动创建钥匙)。
我希望有人可以帮助我,我非常绝望!
这是我的Activity类 包com.bignerdranch.android.taskmanager;
import android.os.Bundle;
import com.google.android.maps.MapActivity;
public class AddLocationMapActivity extends MapActivity {
public static final String ADDRESS_RESULT = "address";
@Override
protected void onCreate(Bundle bundle) {
super.onCreate(bundle);
setContentView(R.layout.add_location);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
@Override
protected boolean isLocationDisplayed() {
return true;
}
}
这是布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/location_title"
.../>
<EditText
android:id="@+id/task_address"
.../>
<Button
android:id="@+id/map_location_button"
.../>
<com.google.android.maps.MapView
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/map_location_button"
android:layout_above="@+id/use_this_location_button"
android:clickable="true"
android:apiKey="AIza.................................." />
<Button
android:id="@id/use_this_location_button"
.../>
</RelativeLayout>
然后,这是清单文件:
?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.bignerdranch.android.taskmanager">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<application
android:name=".TaskManagerApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIza..........................." />
<activity android:name=".ViewTasksActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".AddTaskActivity"
android:text="@string/add_task"/>
<activity android:name=".AddLocationMapActivity"
android:text="@string/add_location_to_task"/>
<uses-library android:name="com.google.android.maps" />
</application>
</manifest>
然后是build.gradle文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 'Google Inc.:Google APIs:24'
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.bignerdranch.android.taskmanager"
minSdkVersion 16
targetSdkVersion 24
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
compile 'com.google.android.gms:play-services-location:10.0.1'
}
最后,这是监视器生成的内容:
12-02 22:37:10.351 22387-22537/com.bignerdranch.android.taskmanager W/System.err: IOException processing: 26
12-02 22:37:10.351 22387-22537/com.bignerdranch.android.taskmanager W/System.err: java.io.IOException: Server returned: 3
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
12-02 22:37:10.352 22387-22537/com.bignerdranch.android.taskmanager W/System.err: at java.lang.Thread.run(Thread.java:818)
我将永远感谢那些可以帮助我解决这个问题的人! Grey tiles instead of map