我在做一個使用Google地圖的應用程序,但地圖沒有顯示,而我看到的唯一的東西是空白方塊。在我的應用程序中顯示的空白地圖
這裏是我的清單:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="fossa.damiano.mapsexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我的活動:
import android.os.Bundle;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapView.LayoutParams;
import com.google.android.maps.MapView;
import android.view.View;
import android.widget.LinearLayout;
public class MainActivity extends MapActivity {
MapView mapView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mapView = (MapView) findViewById(R.id.mapView);
LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
View zoomView = mapView.getZoomControls();
zoomLayout.addView(zoomView,
new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
mapView.displayZoomControls(true);
}
@Override
protected boolean isRouteDisplayed() {
return false;
}
}
而且main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<com.google.android.maps.MapView
android:id="@+id/mapview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:apiKey="My Key" //I've already generated my Key
android:clickable="true" />
</RelativeLayout>
當我嘗試執行我的申請,我智能手機,logcat顯示這些錯誤。
05-31 11:18:01.110: W/System.err(7241): IOException processing: 26
05-31 11:18:01.110: W/System.err(7241): java.io.IOException: Server returned: 3
05-31 11:18:01.115: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:18:01.115: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:18:01.120: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:18:01.120: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:18:01.120: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:18:01.125: W/System.err(7241): at java.lang.Thread.run(Thread.java:856)
05-31 11:18:16.245: W/System.err(7241): IOException processing: 26
05-31 11:18:16.245: W/System.err(7241): java.io.IOException: Server returned: 3
05-31 11:18:16.250: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:18:16.250: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:18:16.250: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:18:16.255: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:18:16.255: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:18:16.255: W/System.err(7241): at java.lang.Thread.run(Thread.java:856)
05-31 11:18:22.070: W/IInputConnectionWrapper(7241): getSelectedText on inactive InputConnection
05-31 11:18:22.070: W/IInputConnectionWrapper(7241): setComposingText on inactive InputConnection
05-31 11:18:22.070: W/IInputConnectionWrapper(7241): getExtractedText on inactive InputConnection
05-31 11:18:27.770: W/IInputConnectionWrapper(7241): showStatusIcon on inactive InputConnection
05-31 11:18:35.120: W/System.err(7241): IOException processing: 26
05-31 11:18:35.130: W/System.err(7241): java.io.IOException: Server returned: 3
05-31 11:18:35.130: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:18:35.130: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:18:35.130: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:18:35.135: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:18:35.135: W/System.err(7241): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:18:35.135: W/System.err(7241): at java.lang.Thread.run(Thread.java:856)
05-31 11:24:28.525: D/dalvikvm(8105): GC_CONCURRENT freed 169K, 14% free 9624K/11143K, paused 13ms+1ms, total 37ms
05-31 11:24:28.535: W/CursorWrapperInner(8105): Cursor finalized without prior close()
05-31 11:24:29.045: D/libEGL(8105): loaded /system/lib/egl/libEGL_mali.so
05-31 11:24:29.080: D/libEGL(8105): loaded /system/lib/egl/libGLESv1_CM_mali.so
05-31 11:24:29.085: D/libEGL(8105): loaded /system/lib/egl/libGLESv2_mali.so
05-31 11:24:29.090: D/(8105): Device driver API match
05-31 11:24:29.090: D/(8105): Device driver API version: 10
05-31 11:24:29.090: D/(8105): User space API version: 10
05-31 11:24:29.090: D/(8105): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Thu Oct 25 08:43:05 KST 2012
05-31 11:24:29.180: D/OpenGLRenderer(8105): Enabling debug mode 0
05-31 11:24:29.185: I/MapActivity(8105): Handling network change notification:CONNECTED
05-31 11:24:29.185: E/MapActivity(8105): Couldn't get connection factory client
05-31 11:24:29.295: D/dalvikvm(8105): GC_CONCURRENT freed 116K, 14% free 9954K/11463K, paused 8ms+20ms, total 53ms
05-31 11:24:29.525: W/System.err(8105): IOException processing: 26
05-31 11:24:29.525: W/System.err(8105): java.io.IOException: Server returned: 3
05-31 11:24:29.660: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:24:29.660: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:24:29.660: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:24:29.660: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:24:29.665: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:24:29.665: W/System.err(8105): at java.lang.Thread.run(Thread.java:856)
05-31 11:24:30.075: W/System.err(8105): IOException processing: 26
05-31 11:24:30.075: W/System.err(8105): java.io.IOException: Server returned: 3
05-31 11:24:30.075: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:24:30.075: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:24:30.080: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:24:30.080: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:24:30.080: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:24:30.080: W/System.err(8105): at java.lang.Thread.run(Thread.java:856)
05-31 11:24:30.535: W/System.err(8105): IOException processing: 26
05-31 11:24:30.535: W/System.err(8105): java.io.IOException: Server returned: 3
05-31 11:24:30.540: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:24:30.540: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:24:30.540: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:24:30.540: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:24:30.540: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:24:30.540: W/System.err(8105): at java.lang.Thread.run(Thread.java:856)
05-31 11:24:30.810: W/System.err(8105): IOException processing: 26
05-31 11:24:30.815: W/System.err(8105): java.io.IOException: Server returned: 3
05-31 11:24:30.815: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:24:30.815: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:24:30.815: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:24:30.825: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:24:30.825: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:24:30.825: W/System.err(8105): at java.lang.Thread.run(Thread.java:856)
05-31 11:24:31.100: W/System.err(8105): IOException processing: 26
05-31 11:24:31.100: W/System.err(8105): java.io.IOException: Server returned: 3
05-31 11:24:31.105: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.BaseTileRequest.readResponseData(BaseTileRequest.java:115)
05-31 11:24:31.105: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.map.MapService$MapTileRequest.readResponseData(MapService.java:1473)
05-31 11:24:31.105: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.processDataRequest(DataRequestDispatcher.java:1117)
05-31 11:24:31.105: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher.serviceRequests(DataRequestDispatcher.java:994)
05-31 11:24:31.105: W/System.err(8105): at android_maps_conflict_avoidance.com.google.googlenav.datarequest.DataRequestDispatcher$DispatcherServer.run(DataRequestDispatcher.java:1702)
05-31 11:24:31.105: W/System.err(8105): at java.lang.Thread.run(Thread.java:856)
我已經啓用了互聯網連接,所以我找不到問題在哪裏。
UPDATE
我已在谷歌地圖從1版本更新到2
下面是變化:
清單:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.pocket_city"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<permission
android:name="com.example.pocket_city.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.pocket_city.permission.MAPS_RECEIVE"/>
<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"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.pocket_city.Home"
android:configChanges="keyboardHidden"
android:label="@string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MonumentMapActivity"
android:label="@string/title_activity_monument_map"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="xxxxxxxxxxxxxxxxx"/>
</application>
</manifest>
活動:
package com.example.pocket_city;
import android.app.Activity;
import android.os.Bundle;
public class MonumentMapActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.monument_map);
}
}
而xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment"/>
</RelativeLayout>
當我嘗試執行它給了我這些錯誤代碼:
06-01 10:12:10.496: E/AndroidRuntime(28178): FATAL EXCEPTION: main
06-01 10:12:10.496: E/AndroidRuntime(28178): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pocket_city/com.example.pocket_city.MonumentMapActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread.access$700(ActivityThread.java:140)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1237)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.os.Handler.dispatchMessage(Handler.java:99)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.os.Looper.loop(Looper.java:137)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread.main(ActivityThread.java:4921)
06-01 10:12:10.496: E/AndroidRuntime(28178): at java.lang.reflect.Method.invokeNative(Native Method)
06-01 10:12:10.496: E/AndroidRuntime(28178): at java.lang.reflect.Method.invoke(Method.java:511)
06-01 10:12:10.496: E/AndroidRuntime(28178): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
06-01 10:12:10.496: E/AndroidRuntime(28178): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
06-01 10:12:10.496: E/AndroidRuntime(28178): at dalvik.system.NativeStart.main(Native Method)
06-01 10:12:10.496: E/AndroidRuntime(28178): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
06-01 10:12:10.496: E/AndroidRuntime(28178): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:313)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Activity.setContentView(Activity.java:1924)
06-01 10:12:10.496: E/AndroidRuntime(28178): at com.example.pocket_city.MonumentMapActivity.onCreate(MonumentMapActivity.java:11)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Activity.performCreate(Activity.java:5206)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
06-01 10:12:10.496: E/AndroidRuntime(28178): ... 11 more
06-01 10:12:10.496: E/AndroidRuntime(28178): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Fragment.instantiate(Fragment.java:584)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Fragment.instantiate(Fragment.java:552)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Activity.onCreateView(Activity.java:4849)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
06-01 10:12:10.496: E/AndroidRuntime(28178): ... 21 more
06-01 10:12:10.496: E/AndroidRuntime(28178): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
06-01 10:12:10.496: E/AndroidRuntime(28178): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
06-01 10:12:10.496: E/AndroidRuntime(28178): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
06-01 10:12:10.496: E/AndroidRuntime(28178): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
06-01 10:12:10.496: E/AndroidRuntime(28178): at android.app.Fragment.instantiate(Fragment.java:574)
06-01 10:12:10.496: E/AndroidRuntime(28178): ... 24 more
更新2
我做了另一個應用程序只顯示地圖和它的作品!
但是,當我試圖將該代碼添加到我的應用程序時,它給出了上面顯示的相同的錯誤!
那麼,爲什麼地圖不能在兩個應用程序上工作?
以及1號使用的是谷歌地圖的棄用版本(V1),IIRC他們不接受任何新的密鑰,你應該使用的地圖V2 – tyczj
我想我是使用地圖的第二個版本。我該如何解決這個問題? – DamianFox
v2是在谷歌播放服務,您需要導入谷歌Play服務,因爲庫項目到您的項目中使用它。搜索堆棧溢出如何做到這一點 – tyczj