문제

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"
          />
도움이 되었습니까?

해결책

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

다른 팁

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

You need to use permission in Manifest

<uses-permission android:name="android.permission.INTERNET"/> 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top