简体   繁体   中英

Google maps api v2. Failed to Load Map. Could not connect to google servers

I an getting this error when I run the application on the real device.

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);*/
    }

}

This is my mainifest file,

 <?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>

I have imported Google play libraries required for the app. Map object is not null. But in the logcat it displays "Google maps Api v2 Failed to load map. Could not connect to google servers"

What I am missing? Please anyone help!! This is killing me!!

Your manifest implies you have entered your signed api key as the google api key, so I assume you're testing this by installing a signed apk on to the device and not running the app signed with the debug key via eclipse. Is this correct?

Problems like this with API access often come down to an input error with the api key, or an error during the hashing process.

I would make sure that the key in your manifest is correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM