Question

I am trying to display Google map inside child fragment on my emulator. But problem is that emulator freezes along with toast displayed continuously while map is loaded like this:

enter image description here

I have checked my manifest file, recreated API key and debug.keystore both. But still it's not working. Please tell me how to tackle with this problem. Thanks.

**Note: ** I am testing on Genymotion emulator - Galaxy S2 API 10(2.3.7). Google play services are already installed on emulator.

AndroidManifest.xml

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

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="18" />
    <uses-permission android:name="android.permission.INTERNET" />
    <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" />
    <uses-permission android:name="com.example.project.permission.MAPS_RECEIVE"/>

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

    <permission
        android:name="com.example.project.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission android:name="android.permission.CALL_PHONE"/>

    <application
        android:hardwareAccelerated="false"
        android:logo="@drawable/ic_drawer1"
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data  android:name="com.google.android.maps.v2.API_KEY"
android:value="api-key"/>

        <uses-library android:name="com.google.android.maps" />
        <activity
            android:name="com.example.project.MainActivity"
            android:label="@string/app_name"
            android:clearTaskOnLaunch="true"  
android:stateNotNeeded="true"
android:theme="@style/Theme.AppCompat" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

MapFragment.java

public class MapFragmentClass extends Fragment implements GooglePlayServicesClient.ConnectionCallbacks,GooglePlayServicesClient.OnConnectionFailedListener,LocationListener  {

    //to extract current loc
    private LocationClient locationclient;
    private LocationRequest locationrequest;
    SupportMapFragment mapFragment;
    GoogleMap map;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.map_fragment, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onViewCreated(view, savedInstanceState);

          FragmentManager fm = getChildFragmentManager();
            mapFragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
            if (mapFragment == null) {
                mapFragment = SupportMapFragment.newInstance();
                fm.beginTransaction().replace(R.id.map, mapFragment).commit();
                fm.executePendingTransactions();

                delayMapLoading();

            }

    }

    void delayMapLoading()
    {
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() 
        {
           @Override
           public void run() {
               map = mapFragment.getMap();

               if(map != null)
                {
                    Log.i("MSG","map is not null");
                    map.setMyLocationEnabled(true);
                 map.setMapType(GoogleMap.MAP_TYPE_SATELLITE);

                }

               else {
                   // handler.postDelayed(this, 500);
               }
           }
          }, 1000);

    }

map_fragment.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >
 <FrameLayout android:id="@+id/map"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1.03"
   android:name="com.google.android.gms.maps.SupportMapFragment" />

</LinearLayout>
Was it helpful?

Solution

if you create your debug.keystore then have you export your app with this same keystore path?

i think you don't have to export your app..

Please export your app with same keystore which is created ..

i hope you solved your problem.

OTHER TIPS

Change your map_fragment.xml

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical" >
 <FrameLayout android:id="@+id/map"
   android:layout_width="match_parent"
   android:layout_height="0dp"
   android:layout_weight="1.03"
   android:name="com.google.android.gms.maps.SupportMapFragment" />

</LinearLayout> 

to

<?xml version="1.0" encoding="utf-8"?>

    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:map="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical" >

     <fragment android:id="@+id/map"
       android:layout_width="match_parent"
       android:layout_height="0dp"
       android:layout_weight="1.03"
       android:name="com.google.android.gms.maps.SupportMapFragment" />

    </LinearLayout>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top