1


我正在做一个使用谷歌地图的应用程序,但地图没有显示,我唯一看到的是空白方块。

这是我的清单:

<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

我制作了另一个只显示地图的应用程序,它可以工作!!
但是当我尝试将该代码添加到我的应用程序时,它给出了上面显示的相同错误!

那么,为什么地图不能在这两个应用程序上工作?

4

2 回答 2

1

文档状态:

https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/MapFragment

关于MapFragment类的使用:

仅当您面向 API 12 及更高版本时才使用此类。否则,使用 SupportMapFragment。

您的最低 SDK 为 11,因此您应该使用SupportMapFragment或更改您的最低 SDK 级别。

于 2013-06-01T13:06:52.893 回答
1

从已弃用的 API v1 迁移到 API v2 的最简单方法是

  1. 删除所有与地图相关的代码
  2. 请点击此链接:https ://developers.google.com/maps/documentation/android/start
于 2013-05-31T16:23:06.167 回答