masmic
masmic

Reputation: 3574

Map not showing

I have a Map inside a fragment. Until now, it showed correctly. Now, I see the Google logo, the +/- buttons and a grey surface with squares (it's not the typical blank background) but I don't see the map.

The logcat is showing continuosly this:

31 11:47:21.413: D/REQUEST(30479): Connection opened to:https://clients4.google.com/glm/mmap/api
10-31 11:47:21.413: D/REQUEST(30479): Open Connection
10-31 11:47:22.294: D/REQUEST(30479): DRD(42): 62|147|7|108
10-31 11:47:22.294: D/REQUEST(30479): Close
10-31 11:47:22.294: D/REQUEST(30479): Error processing: com.google.maps.api.android.lib6.b.d@43ba8a58 not retrying
10-31 11:47:22.304: D/REQUEST(30479): Retrying: com.google.maps.api.android.lib6.c.au@436cc688
10-31 11:47:22.304: D/REQUEST(30479): Retrying: com.google.maps.api.android.lib6.b.v@43900930
10-31 11:47:22.324: D/REQUEST(30479): Retrying: com.google.maps.api.android.lib6.gmm6.m.af@43375668
10-31 11:47:34.246: D/REQUEST(30479): Connection opened to:https://clients4.google.com/glm/mmap/api
10-31 11:47:34.246: D/REQUEST(30479): Open Connection
10-31 11:47:35.277: D/REQUEST(30479): DRD(43): 62|147|7|108
10-31 11:47:35.277: D/REQUEST(30479): Close

Edit- Code added:

private void checkMap() {
    if (mMap == null) {
        /*Try to obtain the map from the SupportMapFragment*/
        mMap = ((SupportMapFragment) getActivity().getSupportFragmentManager().findFragmentById(R.id.map))
                .getMap();
        /*Check if we were successful in obtaining the map.*/
        if (mMap != null) {
            initMap();
        }
    }
}

private void initMap() {
    /*Get location*/
    LocationManager locationManager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
    /*Set criteria*/
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    String provider = locationManager.getBestProvider(criteria, true);
    /*Get last known location if exists*/
    defaultLocation = locationManager.getLastKnownLocation(provider);
    /*If last known location doesn't exist request a single update*/
    if (defaultLocation == null) {
        locationManager.requestSingleUpdate(criteria, new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                defaultLocation = location;
            }
            @Override
            public void onProviderEnabled(String provider) {
            }
            @Override
            public void onProviderDisabled(String provider) {
            }
            @Override
            public void onStatusChanged(String provider, int status, Bundle extras) {
            }
        }, getActivity().getMainLooper());
    }
    /*Move camera*/
    if (defaultLocation != null) {
        mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(
                new LatLng(defaultLocation.getLatitude(), defaultLocation.getLongitude()), 5));
    }
}

Manifest:

<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"/>
<!-- 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"/>

<meta-data 
        android:name="com.google.android.gms.version" 
        android:value="@integer/google_play_services_version" />

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

Upvotes: 1

Views: 1905

Answers (2)

masmic
masmic

Reputation: 3574

Finally I've got a solution. If you use private keystore to apply API_KEY, you cannot upload and install application with eclipse, for that, you have to use a debug key. If you want to see the map using a private keystore, you need to upload .apk file to your device by yourself and install it.

Upvotes: 2

Dilip
Dilip

Reputation: 2734

Please Try Following way

  1. First Check your API Key Generated Is Correctlly and IT Active Or Not API CONSOLE

    1. Add Permission Of Signiture.

    2. Add Permission Of gsf

    3. Check SDK min Version And Max Version

    4. If you run on emulator then you nedd to install these two apk file from cmd pormt. Links for Download...

1)https://www.dropbox.com/s/ccnuqmsxdtb75xl/com.android.vending.apk

Open the AVD
Execute this in the terminal / cmd

adb -e install com.google.android.gms.apk
adb -e install com.android.vending.apk

adb install com.google.android.apps.maps-1.apk
adb install com.google.android.gms-2.apk 

Whole Menefist File

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

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="20" />
    <uses-permission android:name="com.dilip.googlemapsv2.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />



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



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

        <!-- Goolge API Key -->
        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="Your API Generated Key" />                /* Added Bi Dilip */ 
        <meta-data 
            android:name="com.google.android.gms.version" 
            android:value="@integer/google_play_services_version" />
    </application>

</manifest>

Upvotes: 1

Related Questions