3

我已经查看了关于此错误的几乎所有问题,但仍然无法找到它。

这是我的清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.cs2110_final"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <permission
        android:name="com.example.cs2110_final.TheHunt.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.example.cs2110_final.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:glEsVersion="0x00020000"
        android:required="true"/>

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.cs2110_final.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>
        <activity
            android:name="com.example.cs2110_final.TheHunt"
            android:label="@string/title_activity_the_hunt" >
        </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="(API key edited out)" />
    </application>

</manifest>

这是我的活动代码:

mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);

这是对 Map 的 XML 引用:

 <fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true" />

我现在已经完成了整个 API 流程三遍,但没有运气。据我所知,需要在清单中添加的每个权限都已经存在(甚至是偷偷摸摸的 GPS_Services 权限)。有任何想法吗?提前感谢您的帮助!

编辑:这是 LogCat 输出。就是这样,接着是“加载地图失败……”的多次重复

04-19 13:59:03.108: D/dalvikvm(26070): GC_CONCURRENT freed 252K, 6% free 7534K/7940K, paused 4ms+7ms, total 29ms
04-19 13:59:03.138: D/libEGL(26070): loaded /system/lib/egl/libEGL_tegra.so
04-19 13:59:03.148: D/libEGL(26070): loaded /system/lib/egl/libGLESv1_CM_tegra.so
04-19 13:59:03.168: D/libEGL(26070): loaded /system/lib/egl/libGLESv2_tegra.so
04-19 13:59:03.198: D/OpenGLRenderer(26070): Enabling debug mode 0
04-19 13:59:05.968: D/dalvikvm(26070): GC_CONCURRENT freed 301K, 6% free 7654K/8108K, paused 3ms+3ms, total 21ms
04-19 13:59:06.048: D/dalvikvm(26070): GC_CONCURRENT freed 216K, 5% free 7877K/8248K, paused 3ms+2ms, total 29ms
04-19 13:59:06.128: D/dalvikvm(26070): GC_CONCURRENT freed 309K, 6% free 8079K/8540K, paused 3ms+3ms, total 26ms
04-19 13:59:06.128: D/dalvikvm(26070): WAIT_FOR_CONCURRENT_GC blocked 5ms
04-19 13:59:06.128: D/dalvikvm(26070): WAIT_FOR_CONCURRENT_GC blocked 5ms
04-19 13:59:06.128: D/dalvikvm(26070): WAIT_FOR_CONCURRENT_GC blocked 6ms
04-19 13:59:06.128: D/dalvikvm(26070): WAIT_FOR_CONCURRENT_GC blocked 6ms
04-19 13:59:06.198: D/dalvikvm(26070): GC_CONCURRENT freed 250K, 5% free 8330K/8736K, paused 2ms+2ms, total 24ms
04-19 13:59:06.198: D/dalvikvm(26070): WAIT_FOR_CONCURRENT_GC blocked 8ms
04-19 13:59:06.258: D/dalvikvm(26070): GC_CONCURRENT freed 317K, 6% free 8527K/8996K, paused 2ms+3ms, total 25ms
04-19 13:59:06.258: D/dalvikvm(26070): WAIT_FOR_CONCURRENT_GC blocked 10ms
04-19 13:59:06.258: D/dalvikvm(26070): WAIT_FOR_CONCURRENT_GC blocked 10ms
04-19 13:59:06.378: D/dalvikvm(26070): GC_CONCURRENT freed 271K, 5% free 8689K/9128K, paused 2ms+6ms, total 31ms
04-19 13:59:06.378: D/dalvikvm(26070): WAIT_FOR_CONCURRENT_GC blocked 13ms
04-19 13:59:06.398: D/dalvikvm(26070): GC_FOR_ALLOC freed 283K, 8% free 8558K/9260K, paused 23ms, total 23ms
04-19 13:59:06.438: D/dalvikvm(26070): GC_FOR_ALLOC freed 303K, 8% free 8566K/9260K, paused 26ms, total 26ms
04-19 13:59:06.478: D/dalvikvm(26070): GC_FOR_ALLOC freed 325K, 8% free 8567K/9260K, paused 25ms, total 25ms
04-19 13:59:06.518: D/dalvikvm(26070): GC_FOR_ALLOC freed 304K, 8% free 8568K/9260K, paused 25ms, total 25ms
04-19 13:59:06.538: E/Google Maps Android API(26070): Failed to load map.  Could not contact Google servers.
04-19 13:59:06.598: D/dalvikvm(26070): GC_CONCURRENT freed 381K, 8% free 8579K/9260K, paused 6ms+4ms, total 51ms
4

2 回答 2

0

看起来你的问题是这两个权限:

 <permission
    android:name="com.example.cs2110_final.TheHunt.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.cs2110_final.permission.MAPS_RECEIVE" />

从您的包名称来看,这应该是相同的,这意味着如果您在其中写道:

com.example.cs2110_final 

这是你的包名,那么第二个应该是一样的,像这样:

  <permission
    android:name="com.example.cs2110_final.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.example.cs2110_final.permission.MAPS_RECEIVE" />

此外,请确保您遵循生成 API 密钥的所有步骤,您可以遵循我在此主题上编写的本指南:

谷歌地图 API V2 密钥

我在您的代码中看到的另一个问题是您的目标 API 版本 8 ( android:minSdkVersion="8"),因此您应该像现在一样使用SupportMapFragmentandFragmentActivity而不是MapFragmentand a simple 。Activity但据我所知,这与您现在遇到的问题没有任何关系。

你仍然必须改变它,你可以按照我写的这个指南来做:

谷歌地图 API V2

于 2013-05-13T13:13:03.507 回答
0

您检查是否启用了正确的服务?一旦我遇到类似的问题,我的问题是我不小心启用Google Maps API v2Google Maps Android API v2.

请检查您是否为 android 启用了正确的 Google 地图 API 服务,即Google Maps Android API v2.

于 2013-05-13T13:08:34.883 回答