0

I am making a booking app using android studio.I have added a map fragment in it but i get error message getmap() is deprecated and i want use getMapAsync() instead. i tried it but got even more errors.Please help me with it. thanks.

public class HomeActivity  extends Fragment implements View.OnClickListener,GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener,GoogleMap.OnMapClickListener,GoogleMap.OnMarkerDragListener,{
private GoogleMap map;
private static View v;
private GoogleApiClient mGoogleApiClient;
double latitude,longitude;
boolean centeronCurrent= true, syncWithServer= true, trackDriverBoolean= true, waitForRideToEnd=true;
TextView selectPickup, statusText;
Button requesttaxi;
LatLng currentLocation;
int shortestTime;
int nearbyTaxis,taxicount;
String driverid="", currentRideid="";
ArrayList<Marker> markers= new ArrayList<Marker>();


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

    if (v!= null){
        ViewGroup parent= (ViewGroup) v.getParent();
        if (parent!= null)
            parent.removeView(v);
    }
    try {
        v= inflater.inflate(R.layout.home,container,false);
    }
    catch (InflateException e){
        e.printStackTrace();
    }
    map= ((SupportMapFragment)getChildFragmentManager().findFragmentById(R.id.map)).getMap();
    map.setMyLocationEnabled(true);

    map.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    map.setOnMapClickListener(this);
    map.setOnMarkerDragListener(this);

    requesttaxi= (Button) v.findViewById(R.id.request_taxi);
    requesttaxi.setOnClickListener(this);
    statusText=(TextView) v.findViewById(R.id.status_text);
    statusText.setVisibility(View.INVISIBLE);

    SharedPreferences sp = getActivity().getSharedPreferences("Session", Context.MODE_PRIVATE);
    SharedPreferences.Editor editor;
    editor=sp.edit();
    String location= sp.getString("location","");

    mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(LocationServices.API)
            .build();

    selectPickup= (TextView) v.findViewById(R.id.select_location);
    selectPickup.setOnClickListener(this);
    if (location.equals(""))
    {
        selectPickup.setText("Select Pick up Location");
    }
    else {
        String latstr= sp.getString("locationlat","");
        String longstr= sp.getString("locationlong","");
        latitude= Double.parseDouble(latstr);
        longitude= Double.parseDouble(longstr);
        selectPickup.setText(location);

        editor.putString("location","");
        editor.putString("locationlat","");
        editor.putString("locationlong","");
        editor.commit();
        centeronCurrent=false;
    }

    mGoogleApiClient.connect();
    return v;

}
J.Doe
  • 1
  • 1

1 Answers1

0

Your map fragment class must implement OnMapReadyCallback and override onMapReady()

Related to this article: Replace getMap with getMapAsync

Community
  • 1
  • 1
xxx
  • 3,315
  • 5
  • 21
  • 40