Neranja Gunarathne Neranja Gunarathne - 1 year ago 92
Android Question

how can fixed getMap() method in new APIs in android?this method has a error now

please help sample code is

SupportMapFragment mapFragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(;
mMap = mapFragment.getMap();

but it's not working.then i replace getMapAsync(this)method.also but not working my code.please tell me a solution.
thank you.

Answer Source

you need to implement OnMapReadyCallback

public class MainActivity extends Activity implements OnMapReadyCallback{


so code for onCreate() will be

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(;

and overrided method onMapReady() will look like below

public void onMapReady(GoogleMap googleMap) {
    mMap = googleMap;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download