Neranja Gunarathne Neranja Gunarathne - 1 year ago 146
Android Question

getMap() method in new Android API is not working properly for me

Sample code:

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

but it is not working as expected.

Then I replace
. Still it´s not working.

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