我正在做一个使用谷歌地图的应用程序,但地图没有显示,我看到的唯一的是空白方块。
这是我的清单:
<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)
我已启用互联网连接,因此无法找出问题所在。
更新
我已将Google地图的版本从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
我做了另一个只显示地图的应用程序,它可以工作!!
但是当我尝试将该代码添加到我的应用程序时,它会显示上面显示的相同错误!
那么,为什么地图不能同时适用于两个应用程序?
答案 0 :(得分:1)
从弃用的API v1迁移到API v2的最简单方法是
答案 1 :(得分:1)
文档声明:
关于使用MapFragment
类:
仅在您定位API 12及更高版本时才使用此课程。否则,请使用SupportMapFragment。
你最近SDK是11因此你应该使用SupportMapFragment
或更改你的最低SDK级别。