Cannot resolve method getMap()

The getMap() method was previously deprecated, and now it’s been removed. If you look at the documentation for SupportMapFragment, it’s not there.

You can also see in the release notes:

The previously-deprecated getMap() function is no longer available in
the Google Play services SDK. (It is still available in the Google
Play services APK that is delivered to Android devices.) The getMap()
function has been deprecated since December 2014. See the release blog
post
for help with converting from getMap() to getMapAsync().

And from the blog post:

In December 2014 we deprecated getMap() in favor of getMapAsync().
From this release onwards, you’ll need to use getMapAsync() in order
to compile your apps.

So, just use getMapAsync(), it’s simple.

First have your Fragment implement the OnMapReadyCallback interface:

public class FragmentWithMap extends android.support.v4.app.Fragment
          implements OnMapReadyCallback { 

Then, modify your setUpMapIfNeeded() code, and add the onMapReady() callback:

private void setUpMapIfNeeded() {
  if (mMap == null) {
    SupportMapFragment mapFrag = (SupportMapFragment) getChildFragmentManager().findFragmentById(R.id.fragment_map2);
    mapFrag.getMapAsync(this);
  }
}

@Override
public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
    setUpMap();
}

Leave a Comment