2

When I call moveCamera on a small screen, it throws the following exception:

java.lang.IllegalStateException: Illegal height.

This is my code:

googleMap.moveCamera(
    CameraUpdateFactory.newLatLngBounds(
        bounds,
        // Padding
        100,
    ),
)

I tried removing the padding, but it makes no difference.

I guess this problem has to do with the limited height available to render the map as this only occurs on small screens, but there is still quite some space left for the map to render so I wouldn't expect a crash.

How do I render the map and move the camera to the given bounds?


Dependency versions:

  • com.google.android.libraries.maps:maps:3.1.0-beta
  • com.google.maps.android:maps-v3-ktx:2.2.0
  • androidx.compose.ui:ui:1.0.0-rc02
Duncan Lukkenaer
  • 12,050
  • 13
  • 64
  • 97
  • https://stackoverflow.com/questions/33046704/illegalstateexception-view-size-is-too-small-after-padding Refer to this – Akash Pal Aug 06 '21 at 10:30
  • I faced the same problem already. My solution is checking if the google map fragment view' height and width are larger than 0 or not before moving camera. – TaQuangTu Aug 06 '21 at 10:31

1 Answers1

3

Even though the crash happened on moveCamera, the problem seemed to be caused by setPadding called above it:

googleMap.setPadding(
    0,
    topPadding,
    0,
    0,
)

The fix was making sure that the padding would not exceed half of the map size:

googleMap.setPadding(
    0,
    min(topPadding, map.height / 2 - 2),
    0,
    0,
)
Duncan Lukkenaer
  • 12,050
  • 13
  • 64
  • 97