0

hello everyone... the next code should open a google map but when run it return an empty map any reason why it returns empty

I dont know how to return amap not an empty map..

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

        try {
            // Loading map
            initilizeMap();

    } catch (Exception e) {
        e.printStackTrace();
    }
}

private void initilizeMap() {
        if (googleMap == null) {
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();

            // check if map is created successfully or not
            if (googleMap == null) {
                Toast.makeText(getApplicationContext(),
                        "Sorry! unable to create maps", Toast.LENGTH_SHORT)
                        .show();
            }
        }
    }

xml file

<fragment
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          class="com.google.android.gms.maps.MapFragment"
          />
kura
  • 45
  • 1
  • 6

3 Answers3

0

You have to set google map key in AndroidManifest.xml. Then meta-data tag like

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

And also follow this tutorial

Simmant
  • 1,477
  • 25
  • 39
Sachin Shelke
  • 449
  • 4
  • 12
0

You need to use permission in Manifest

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

This issue can occur if you use the wrong debug keystore to generate the api key. If you're working in ubuntu it's possible you're opening the ide in root, which means the debug keystore being used to sign the app is the one in the root folder(/root/.android/debug.keystore) whiles you probably used the debug keystore in your user folder for creating the api key. Please check and make sure you are using the right one. I have also added a link to an answered question with a similar issue: Google Maps V2 shows blank screen on android 2.2

Community
  • 1
  • 1
euniceadu
  • 868
  • 16
  • 34
  • the file debug.keystoreand is empty file ! – kura Mar 30 '14 at 13:38
  • which directory did you check and which OS are you using? if you are using ubuntu, start eclipse as root and check Preferences->Android->Build, the value for the Default debug keystore field should be /root/.android/debug.keystore. The sha1 fingerprint needed to obtain the api key is also stated in the 3rd field. just remember to always start eclipse as root when you want to work on that particular app – euniceadu Mar 30 '14 at 17:22
  • Im using Windows 7 the path :.android/debug.keystore its already there but no data insid – kura Mar 31 '14 at 09:09
  • if there's no data in it, then you can always create a new one with this command: keytool -genkey -v -keystore "\debug.keystore" -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US" – euniceadu Mar 31 '14 at 10:51