2

I'm using MapFragment, my activity layout is it:

<fragment
        android:id="@+id/map"
        android:name="com.google.android.gms.maps.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/actionbar" />

If I want to move map camera using CameraUpdateFactory.newLatLngBounds(LatLngBounds, padding) I get this error:

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.

Is there an event listener if the map has measured?

EDIT1: @raz that is the code where I retrieve the map fragment:

if (googleMap == null) {
            googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                    R.id.map)).getMap();
}
parse
  • 1,706
  • 17
  • 27
  • Could you post the code where you retrieve the map fragment, as well as the map? – RoraΖ Jul 17 '14 at 15:05
  • ditto it's important that correctly get the map fragment before operating on the map. – danny117 Jul 17 '14 at 19:31
  • @raz I have posted the code, sorry for the delay. – parse Jul 18 '14 at 11:55
  • This two posts would help. http://stackoverflow.com/questions/14419334/android-googlemaps-v2-finish-loading-event-or-callback http://stackoverflow.com/questions/18377498/detect-when-android-v2-maps-has-loaded – Gavin Jul 18 '14 at 12:06

1 Answers1

6

I found this solution thanks to @Gavin:

googleMap.setOnMapLoadedCallback(new OnMapLoadedCallback() {
    @Override
    public void onMapLoaded() {
        Log.i(TAG_LOG_I, "Map loaded successfully :)");
    }
});
parse
  • 1,706
  • 17
  • 27