How to get bounds of visible map with flutter google_maps plugin?
That would be GoogleMapController.getVisibleRegion()
Be careful, GoogleMapController.getVisibleRegion()
returns a LatLngBounds
(a rectangle) and if your map has a tilt then it should not be a rectangle but a trapezoid!
The issue is in the plugin implementation where the returned result is computed only from latLngBounds
field whereas it should be computed from farLeft
, farRight
, nearLeft
, nearRight
fields.
Reference: https://developers.google.com/maps/documentation/android-sdk/reference/com/google/android/libraries/maps/model/VisibleRegion
So GoogleMapController.getVisibleRegion()
is not accurate and can't be used if there's a tilt.
For reference, an issue has been created: https://github.com/flutter/flutter/issues/74888