0

I am using NavigationDrawer in my project and I am implementing google maps, but I'm unable to do that because of getSupportFragmentManager(), It always giving the error:

The method getSupportFragmentManager() is undefined for the type MapView.

Here is code:

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;

import android.annotation.SuppressLint;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

@SuppressLint("NewApi")
public class MapView extends Fragment {


    private Context context = getActivity();

    public MapView(){}

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.map_view, container, false);

        GoogleMap gMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

        int result = GooglePlayServicesUtil.isGooglePlayServicesAvailable(context);
        Log.e("Maps", "Result int value::" + result);
        switch (result) {
        case ConnectionResult.SUCCESS:
            Log.e("Maps", "RESULT:: SUCCESS");          
            break;

        case ConnectionResult.DEVELOPER_ERROR:
            Log.e("Maps", "RESULT:: DE");           
            break;

        case ConnectionResult.INTERNAL_ERROR:
            Log.e("Maps", "RESULT:: IE");           
            break;

        case ConnectionResult.INVALID_ACCOUNT:
            Log.e("Maps", "RESULT:: IA");           
            break;

        case ConnectionResult.NETWORK_ERROR:
            Log.e("Maps", "RESULT:: NE");           
            break;

        case ConnectionResult.RESOLUTION_REQUIRED:
            Log.e("Maps", "RESULT:: RR");           
            break;

        case ConnectionResult.SERVICE_DISABLED:
            Log.e("Maps", "RESULT:: SD");           
            break;

        case ConnectionResult.SERVICE_INVALID:
            Log.e("Maps", "RESULT:: SI");           
            break;

        case ConnectionResult.SERVICE_MISSING:
            Log.e("Maps", "RESULT:: SM");           
            break;
        case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
            Log.e("Maps", "RESULT:: SVUR");         
            break;
        case ConnectionResult.SIGN_IN_REQUIRED:
            Log.e("Maps", "RESULT:: SIR");          
            break;      

        default:
            break;
        }
        gMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
        gMap.setMyLocationEnabled(true);
        Log.e("Maps", "------EOC-------");

        return rootView;
    }

}
pinepain
  • 12,453
  • 3
  • 60
  • 65
Tapsee Panu
  • 387
  • 4
  • 11
  • 1
    check this http://stackoverflow.com/questions/20919048/android-android-view-inflateexception-binary-xml-file-line-8-error-inflatin – Raghunandan Jul 07 '14 at 11:39

1 Answers1

0
import fragment from android.support.v4.app.Fragment;
and just change 

    GoogleMap gMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();

    to 

    GoogleMap gMap = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
Imran Betara
  • 649
  • 3
  • 8
  • Sorry dude after follow steps, i'm getting this:- Cannot cast from Fragment to SupportMapFragment... – Tapsee Panu Jul 07 '14 at 11:58
  • however i'm also using the map in my fragment but i dont get this type of error. please make sure that you have imported fragment like this import android.support.v4.app.Fragment; – Imran Betara Jul 07 '14 at 12:19