Neranja Gunarathne Neranja Gunarathne - 4 months ago 38
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.


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;