1

I'm using Google map V2 in my project, I'm instantiating map in baseadapter class (setting in listview),

Layout file:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="fill_parent"
    android:layout_height="500dp"
    android:layout_margin="10dp" />

Java code:

private void setUpMap()
{
    // Do a null check to confirm that we have not already instantiated the map.
    if (ViewHolder.mMap == null)
    {


        android.app.FragmentManager fm = ((Activity) context).getFragmentManager();

        // Try to obtain the map from the SupportMapFragment.
        ViewHolder.mMap = ((MapFragment) fm.findFragmentById(R.id.map)).getMap();

        //=======clear old marker====
        ViewHolder.mMap.clear();

        // Check if we were successful in obtaining the map.

        if (ViewHolder.mMap != null)
        {
            ViewHolder.mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener()
            {
                @Override
                public boolean onMarkerClick(com.google.android.gms.maps.model.Marker marker)
                {
                    marker.showInfoWindow();
                    return true;
                }
            });
        }
        else
            Toast.makeText(context, "Unable to create Maps", Toast.LENGTH_SHORT).show();
    }
}

I've all the known permission for map.

    <permission android:name="com.the.app.rr.permission.MAPS_RECEIVE"  
android:protectionLevel="signature" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="******_n3wx2Ga-6lBLpD1v56SXs3IIxEqyKw" />
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

I'm working on it for last two days, and check all, anything didn't work for me..

Logs getting from Google.

1. I/Google Maps Android API(26592): Google Play services package version: 5089038
2. Failed resolving Lcom/google/android/gms/location/internal/ParcelableGeofence; interface 4023 'Lglm;'
3. Could not find class 'com.google.android.gms.location.internal.ParcelableGeofence', referenced from method gls.a
4. Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

Can anyone help please?

Simas
  • 43,548
  • 10
  • 88
  • 116
Ankit
  • 483
  • 7
  • 24
  • Are you sure that your api key is true? How did you create your api key? – Burak Sep 17 '14 at 11:12
  • @Burak I've follow all steps as mentioned on developers site. and for counter check I've created second project on console but that key also did't work. – Ankit Sep 17 '14 at 11:23
  • Did you use keytool.exe in cmd for getting SHA1 key? – Burak Sep 17 '14 at 11:26

1 Answers1

0
  • You are calling ViewHolder.mMap.clear() before you check ViewHolder.mMap != null

  • Are you calling setUpMap from onCreate ?, if so I would try moving it to onResume so the map handling is done at later stage in life cycle.

  • In case of ViewHolder.mMap == null i would call MapsInitializer.initialize(getActivity()) to make sure GoogleMap initialization is kicked off. It should not be necessary, but can help.

  • I ran into this issue before, and I realized it was due to the API key. I had to generate a fresh Android key using the debug keystore on my local machine, as the android studio is using it for builds. In my case I had to get the SHA1 from:

    keytool -list -v -keystore %HOMEPATH%\.android\debug.keystore

  • Another potential issue is the mismatch between the google play services library version you are using in your android app, and the play services apk version on the device or emulator. They need to match or at least the one on your app should be less or equal. You can find out the Google Play Services version on the device or emulator via Settings -> Apps -> Downloaded -> Google Play Services. If this version is less than the library version you use in android app, i would try with older version library.

Finding Google Play Services version

ashoke
  • 6,441
  • 2
  • 26
  • 25