0

i am trying google maps using a tutorial, but it doesnt show the map; just the grey tiles. please help me.. My project is stuck because of this.

Here is my code

following is the EDITED code i tried again. please have a look at the code and the logcat file.

Manifest file

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

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

     <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <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" />
    <!--
     The following two permissions are not required to use
     Google Maps Android API v2, but are recommended.
    -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

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

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

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

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

    </application>


</manifest>

activity_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

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

</RelativeLayout>

MainActivity.java

package com.example.googlemapsv2;

import android.os.Bundle;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.view.Menu;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;


public class MainActivity extends Activity {

     GoogleMap map;
     @SuppressLint("NewApi")

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

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



}

Logcat

10-17 19:16:53.750: E/Google Maps Android API(9452): Authorization failure.  Please see https://developers.google.com/maps/documentation/android/start for how to correctly set up the map.
10-17 19:16:53.750: E/Google Maps Android API(9452): Ensure that the following correspond to what is in the API Console: Package Name: com.example.googlemapsv2, API Key: AIzaSyCmYChMyMqZCj5nZl-lykGioJwNGW-hTCA, Certificate Fingerprint: 5A6683F0B22028AFBFF49C0EC90FCFA015AA20C6
10-17 19:16:53.773: I/Google Maps Android API(9452): Failed to contact Google servers. Another attempt will be made when connectivity is established.
hina fatima
  • 83
  • 1
  • 8
  • How did you generate that apikey? Did you use the one from the tutorial? – Marcelo Oct 15 '13 at 20:01
  • NO, i generated the google map api V2 .. not the deprecated one – hina fatima Oct 15 '13 at 20:05
  • You are using the Google Maps V1 classes. Check my answer here http://stackoverflow.com/questions/15041200/google-maps-api-key-not-working-v2/15041476#15041476 – Marcelo Oct 15 '13 at 20:08
  • You should probably not post your API key here either. I would generate a new one. – telkins Oct 15 '13 at 20:11
  • @trevor-e When you register the key, you set your application package and your keystore fingerprint. That makes it hard to anyone else use the same key, but I would generate a new one too. – Marcelo Oct 15 '13 at 20:15
  • possible duplicate of [Map only displays tiles](http://stackoverflow.com/questions/13611635/map-only-displays-tiles) and [many others...](http://stackoverflow.com/search?q=%5Bandroid%5D+maps+gray+tiles) – Geobits Oct 17 '13 at 14:29

3 Answers3

2

See here,just change the api key with your key in manifest file and follow these steps: and make sure that your google_play_services_lib project should be present in your project's work space only.

Manifest file:

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

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

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

        <meta-data
    android:name="com.google.android.maps.v2.API_KEY"
    android:value="replace with your API key"/>

    </application>

</manifest>

MainActivity.java:

    package com.geeklabs.map;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

}

activity_main.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"
          android:name="com.google.android.gms.maps.MapFragment"/>

After got this let me know.

Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
  • the activity_main's first line – hina fatima Oct 17 '13 at 15:12
  • k, remove previous code from activity_main.xml and place it with i posted one. And just ignore lint warnings by right click on your project -->Android Tools-->clear lint markers. May be it might helps. – Shailendra Madda Oct 17 '13 at 15:22
  • So it is problem with your API key, create new API key with your SHA-1 key and package name(mentioned in Android manifest.xml) separated with semi column. – Shailendra Madda Oct 17 '13 at 15:29
  • Thankssss. finally the map is shown :) btw tell me one thing. now if i want to add this map in my other project do i need to create another key ? – hina fatima Oct 17 '13 at 15:37
  • Yes, you need to create one more API key with same sha-1 key separated with package name which is mentioned in android manifest file – Shailendra Madda Oct 19 '13 at 06:34
  • If you got my solution let me know and say it is useful answer for you. – Shailendra Madda Oct 19 '13 at 06:36
  • today i tried creating a new api key to get maps in my other project, but it gives me error 10-23 23:28:28.418: E/Google Maps Android API(4787): Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors). – hina fatima Oct 23 '13 at 18:29
  • @hinafatima This is issue with your API key and also Make sure the "Google Maps Android API v2" and "Google Play Android Developer API" are enabled in API Console – Shailendra Madda Jul 14 '14 at 10:37
  • Refer this might helps you http://stackoverflow.com/questions/17667935/failed-to-load-map-error-contacting-google-servers-this-is-probably-an-authent – Shailendra Madda Jul 14 '14 at 10:38
0

The map is not working because your manifest is not set up correctly. User this tutorial from the Android documentation and make sure you enable the exact permissions required. Also your API key is in the wrong place. It goes in your manifest, not in the fragment.

Rarw
  • 7,645
  • 3
  • 28
  • 46
-1

There is some issue with Google maps version 2 while loading on certain devices, you just have to restart the device and it will start working.

Asheesh
  • 565
  • 6
  • 21