0

我正在尝试使用新的 api 在我的应用程序中显示地图,但我得到的只是:

“Google Play 服务的未知问题”

这是我的清单:

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

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

<uses-permission android:name="android.permission.INTERNET"/> 

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


<uses-permission android:name="com.example.monitoringsensors.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<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.monitoringsensors.Title"
        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.monitoringsensors.HttpExample"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.HTTPEXAMPLE" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

     <activity
        android:name="com.example.monitoringsensors.TakeSomeData"
        android:label="@string/app_name" 
        android:theme="@android:style/Theme.Dialog">
        <intent-filter>
            <action android:name="android.intent.action.TAKESOMEDATA" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>



     <meta-data android:name="com.google.android.maps.v2.API_KEY"
           android:value="AIzaSyCW3iv83siHrkWM6Q2qV4YcXk27CZWwmqc"></meta-data>

</application>

</manifest>

这是 XML 文件:

    <?xml version="1.0" encoding="utf-8"?>
    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment"/>

这个类是这样调用的:

  public class HttpExample  extends android.support.v4.app.FragmentActivity {...}

谢谢小伙伴们!

4

2 回答 2

1

您需要验证地图可用性 在与 GoogleMap 对象交互之前,您需要确认对象可以被实例化,并且 Google Play 服务组件已正确安装在目标设备上。您可以通过调用 MapFragment.getMap() 或 MapView.getMap() 方法并检查返回的对象是否为空来验证 GoogleMap 是否可用。 https://developers.google.com/maps/documentation/android/map#verify_map_availability

于 2012-12-17T20:49:25.973 回答
0

我个人使用此代码来检查 Google Play 服务,我在运行 2.3.3 的真实设备和各种版本的操作系统上的模拟器上进行测试,它可以防止模拟器崩溃,因为它们没有附带更新的 Google Play 服务启用 v2 的 Android 谷歌地图。
protected boolean readyToGo() {

String TAG_ERROR_DIALOG_FRAGMENT="errorDialog";

int status= GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
    if (status == ConnectionResult.SUCCESS) {
      return(true);
    }
    else if (GooglePlayServicesUtil.isUserRecoverableError(status)) {
      ErrorDialogFragment.newInstance(status)
                         .show(getSupportFragmentManager(),
                               TAG_ERROR_DIALOG_FRAGMENT);
    }
    else {
      Toast.makeText(this, "no maps", Toast.LENGTH_LONG).show();
      finish();
    }

    return(false);
  }

如果它能够显示地图,则返回 true,这意味着设备具有所需的 Google Play 服务;如果没有,则返回 false,Eclipse 中的标准模拟器等现在就是这种情况。

于 2012-12-20T22:00:13.760 回答