7

Can anyone explain the difference between

OnMapReadyCallback.OnMapReady(GoogleMap googleMap)

and

GoogleMap.OnMapLoadedCallback.OnMapLoaded()

It is not very clear to me.

Daniele B
  • 19,801
  • 29
  • 115
  • 173

1 Answers1

11

It basically depends upon what you want to do with the map.

You can safely use OnMapReadyCallback to set your pins, etc. It is called as soon as the map is ready for you to use it.

OnMapLoadedCallback, as the docs state, is called

When the map has finished rendering. This occurs after all tiles required to render the map have been fetched, and all labeling is complete. eg. the map's content is fully loaded and visible.

This happens later than OnMapReady. The call googleMap.setOnMapLoadedCallback even implies that OnMapReady already happened to be able to be called safely (googleMap != null).

Gaurav Sarma
  • 2,248
  • 2
  • 24
  • 45
  • 5
    Currently I randomly get this error when I call `googleMap.animateCamera()` after `OnMapReady`: `Error using newLatLngBounds(LatLngBounds, int): Map size can't be 0. Most likely, layout has not yet occured for the map view. Either wait until layout has occurred or use newLatLngBounds(LatLngBounds, int, int, int) which allows you to specify the map's dimensions.` Would the issue be resolved is I call it after `OnMapLoaded` ? – Daniele B Aug 30 '16 at 16:57
  • That is a different question altogether and there are few suggestions here http://stackoverflow.com/questions/25231949/add-bounds-to-map-to-avoid-swiping-outside-a-certain-region – Gaurav Sarma Aug 30 '16 at 17:00
  • thanks for the link, also the accepted answer there suggests to use `googleMap.setOnMapLoadedCallback` – Daniele B Aug 30 '16 at 17:09
  • 1
    Glad was able to help best of luck – Gaurav Sarma Aug 30 '16 at 17:18