"Error using newLatLngBounds(LatLngBounds, int): Map size can't be zero...." using react-native-maps on Android

raph picture raph · Dec 9, 2017 · Viewed 10.2k times · Source

I get an error: "Error using newLatLngBounds(LatLngBounds, int): Map size can't be zero. 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".

But I set up an alert for getCurrentPosition and I'm receiving coordinates from getCurrentPosition().

I have no idea what's going wrong to be honest... would really appreciate some help! Thank you!!

Answer

Elad picture Elad · Feb 26, 2020

this happens because the map view was not initialized yet. move the call to within the onMapLoaded overriden event. within your

  @Override
    public void onMapReady(GoogleMap googleMap)

add :

googleMap.setOnMapLoadedCallback(new GoogleMap.OnMapLoadedCallback() {
                    @Override
                    public void onMapLoaded() {
                        //Your code where the exception occurred goes here    
                    }
                });