I am using getMapAsync() instead of getMap() in mapview.But, I wish to know the difference between getMap() and getMapAsync.
            Asked
            
        
        
            Active
            
        
            Viewed 919 times
        
    -3
            
            
         
    
    
        sabith.ak
        
- 255
- 4
- 12
- 
                    1I think you should need to read https://stackoverflow.com/questions/748175/asynchronous-vs-synchronous-execution-what-does-it-really-mean this link – ADNAN ZAMAN Nov 16 '17 at 09:41
- 
                    3you can't read? Like, documentation? – Tim Nov 16 '17 at 09:49
3 Answers
2
            
            
        So, getMapAsync should be used as it waits till the map is properly initialized and provides the Map instance via a callback.
public class MapActivity extends Activity implements OnMapReadyCallback {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.map_activity);
        MapFragment mapFrag = (MapFragment) getFragmentManager()
                .findFragmentById(R.id.map);
        mapFrag.getMapAsync(this);
    }
    @Override
    public void onMapReady(GoogleMap map) {
        // Place your logic here
        map.setIndoorEnabled(true);
        map.setBuildingsEnabled(true);
        map.getUiSettings().setZoomControlsEnabled(false);
    }
}
 
    
    
        Nayan Srivastava
        
- 3,655
- 3
- 27
- 49
1
            getMap() is deprecated
public void getMapAsync (OnMapReadyCallback callback)Sets a callback object which will be triggered when the GoogleMap instance is ready to be used.
Note that:
- This method must be called from the main thread. 
- The callback will be executed in the main thread. 
- In the case where Google Play services is not installed on the user's device, the callback will not be triggered until the user installs it. 
- In the rare case where the GoogleMap is destroyed immediately after creation, the callback is not triggered. 
- The GoogleMap object provided by the callback is non-null. 
 
     
    