我已經試了又試,並試圖弄清楚這個問題了。我到處搜索,我還沒有找到解決方案。我明白在這個主題上有很多論壇,但沒有人幫助我想出一個解決方案。錯誤與谷歌API的Android應用程序利用MapActivity
我遇到的問題是,當我運行我的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'
}
最後一點,這是由Monito生成的r:
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
教程這是我的問題!謝謝!但是,您是否有任何關於如何將此特定代碼「翻譯」到V2的指示? – AlwaysWin
V2版本是如此不同,我在答覆中增加了一個教程,只要按照這 –