Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get bounds of visible map with flutter google_maps plugin?

I'm trying to find out what is the bounding box of the visible part of google map in flutter's google maps plugin.

Is it possible to get it?

If not is it possible to calculate the bounding box based on zoom level and latitude, longitude of the map center?

like image 703
user4401 Avatar asked Mar 15 '19 16:03

user4401


People also ask

How do you get the map location in Flutter?

Step 1: Add location and syncfusion_flutter_maps packages to your dependencies in pubspec. yaml file. Step 2: Import the below libraries in your dart file. Step 3: Using the public APIs in the Flutter location package, we can get the current location.


2 Answers

That would be GoogleMapController.getVisibleRegion()

like image 199
Maik Mewes Avatar answered Sep 18 '22 08:09

Maik Mewes


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

like image 22
Eric Taix Avatar answered Sep 17 '22 08:09

Eric Taix