-3

I am using getMapAsync() instead of getMap() in mapview.But, I wish to know the difference between getMap() and getMapAsync.

sabith.ak
  • 220
  • 3
  • 11

3 Answers3

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,515
  • 3
  • 26
  • 48
1

getMapAsync let you use a callback when the map is init ;)

andrea06590
  • 1,181
  • 2
  • 9
  • 20
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.

Community
  • 1
  • 1
Goku
  • 8,341
  • 7
  • 43
  • 73