Question

I know this has been an asked and reasked question but however i get this strange behaviour. No crashes but the map is not loading anymore.

I am trying to use Google Maps for my Android application. I managed to load my map yesterday but today when i tried running the app i get the following error:

08-01 10:40:50.374: I/Google Maps Android API(5605): Failed to contact Google servers. Another attempt will be made when connectivity is established.
08-01 10:41:05.649: E/Google Maps Android API(5605): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

This is my Activty where i try to open the map:

public class LocationActivity extends Activity {

    private GoogleMap map;
    private RelativeLayout cancel_btn;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().requestFeature(Window.FEATURE_ACTION_BAR);
        getActionBar().hide();
        setContentView(R.layout.preview_location);
        cancel_btn = (RelativeLayout) findViewById(R.id.cancel_btn);

        cancel_btn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map))
                .getMap();

        if (map != null) {
            retrieveLocation();
        } else {

        }

    }

    @Override
    public void onBackPressed() {
        map.clear();
        super.onBackPressed();
    }

    private void retrieveLocation() {
        Intent intent = getIntent();
        String staddress = intent.getStringExtra("location");
        Geocoder geocoder = new Geocoder(this, Locale.US);

        try {
            List<Address> loc = geocoder.getFromLocationName(staddress, 5);
            double latitude = loc.get(0).getLatitude();
            double longitude = loc.get(0).getLongitude();

            map.addMarker(new MarkerOptions().position(
                    new LatLng(latitude, longitude)).title(staddress));

            map.moveCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(latitude, longitude), 12));

            // Zoom in, animating the camera.
            map.animateCamera(CameraUpdateFactory.zoomTo(12), 2000, null);

        } catch (IOException e) {
            Log.e("IOException", e.getMessage());
            Toast.makeText(this, "IOException:  " + e.getMessage(), Toast.LENGTH_LONG).show();
        }

    }

}

And the XML:

<fragment
        android:layout_weight="6"
        android:id="@+id/map"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        class="com.google.android.gms.maps.MapFragment"/>

Manifest XML:

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

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <uses-feature
        android:name="android.hardware.camera"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.back"
        android:required="false" />
    <uses-feature
        android:name="android.hardware.camera.autofocus"
        android:required="false" />

    <permission
        android:name="ro.gebs.captoom.maps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-sdk
        android:minSdkVersion="12"
        android:targetSdkVersion="17" />

    <uses-permission android:name="android.permission.CAMERA" />
    <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" />

    <application
        android:name="ro.gebs.captoom.utils.CaptoomApplication"
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data
            android:name="AA_DB_NAME"
            android:value="captoom.db" />
        <meta-data
            android:name="AA_DB_VERSION"
            android:value="1" />

        <uses-library android:name="com.google.android.maps" />

        <activity
            android:name="ro.gebs.captoom.activities.HomeActivity"
            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="ro.gebs.captoom.activities.TakePicture" >
        </activity>
        <activity android:name="ro.gebs.captoom.activities.PreviewPhoto" >
        </activity>
        <activity android:name="ro.gebs.captoom.activities.AddReceiptActivity" >
        </activity>
        <activity android:name="ro.gebs.captoom.activities.EditReceiptActivity" >
        </activity>
        <activity android:name="ro.gebs.captoom.activities.LocationActivity" >
        </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyAzIsgylRUb3yxrh-9BsgBJcVo0M4UOhyU" />
    </application>

</manifest>

I updated my API Key today still no result... any ideas?

Was it helpful?

Solution

brother do you give all the permission and changed the package name according to your Google Api key. Now you have to paste your manifest file code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top