1

当我在真实设备上运行应用程序时出现此错误。

Main_Activity.java,

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    int chkGooglePlayServices = GooglePlayServicesUtil
            .isGooglePlayServicesAvailable(Context);
    if (chkGooglePlayServices != ConnectionResult.SUCCESS) {
        GooglePlayServicesUtil.getErrorDialog(chkGooglePlayServices,
                (Activity) Context, 1122).show();
    } else {
        SupportMapFragment sfm = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mMap = sfm.getMap();

        mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        Criteria criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        // Location Update
        LocationListener listener = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                mMap.clear();
                final CameraPosition cameraPosition = new CameraPosition.Builder()
                        .target(new LatLng(location.getLatitude(), location
                                .getLongitude())).zoom(14.0f).build();
                final CameraUpdate cameraUpdate = CameraUpdateFactory
                        .newCameraPosition(cameraPosition);
                mMap.moveCamera(cameraUpdate);
            }

            AlertDialog.Builder dialog = new AlertDialog.Builder(Context)
                    .setTitle(R.string.RemindEnableGps);
            AlertDialog alert = dialog.create();

            @Override
            public void onProviderDisabled(String provider) {
                alert.setCanceledOnTouchOutside(false);
                alert.setCancelable(true);
                alert.show();

            }

            @Override
            public void onProviderEnabled(String provider) {
                alert.dismiss();

            }

            @Override
            public void onStatusChanged(String provider, int status,
                    Bundle extras) {
            }
        };

        lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
                listener);
        final Location mLocation = lm
                .getLastKnownLocation(LocationManager.GPS_PROVIDER);

        /*final CameraPosition cameraPosition = new CameraPosition.Builder()
                .target(new LatLng(mLocation.getLatitude(), mLocation
                        .getLongitude())).zoom(14.0f).build();
        final CameraUpdate cameraUpdate = CameraUpdateFactory
                .newCameraPosition(cameraPosition);
        mMap.moveCamera(cameraUpdate);*/
    }

}

这是我的主要文件,

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

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

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

<uses-permission android:name="com.example.findproperty.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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.findproperty.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>
    <uses-library android:name="com.google.android.maps" />

    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="Given my signed key" />

   </application>

</manifest>

activity_main.xml,

 <?xml version="1.0"?>

<fragment 
    android:id="@+id/map"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginBottom="30dp"
    android:layout_marginLeft="30dp"
    android:layout_marginRight="30dp"
    android:layout_marginTop="60dp"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:clickable="true" />

</RelativeLayout>

我已经导入了应用程序所需的 Google Play 库。地图对象不为空。但在 logcat 中它显示“Google maps Api v2 Failed to load map. could not connect to google servers”

我错过了什么?请任何人帮助!这要死我了!!

4

1 回答 1

0

您的清单意味着您已将签名的 api 密钥作为 google api 密钥输入,因此我假设您通过在设备上安装签名的 apk 来测试这一点,而不是通过 eclipse 运行使用调试密钥签名的应用程序。这个对吗?

像这样的 API 访问问题通常归结为 api 密钥的输入错误,或哈希过程中的错误。

我会确保您的清单中的密钥是正确的。

于 2013-04-25T09:32:36.157 回答