flutterlocationgoogle-maps-flutter

Get map center point on scrolling Google maps flutter


I'm doing an app in my app. I'm using google maps flutter and I'm having an issue regarding scrolling. When I scroll the map I want to get the center points (long, lat) of the map that is if I scroll the map and stop at certain place it would grab the location points of center.

Can anyone suggest how to solve this issue? It can be very helpful Thank you in advance..


Solution

  • I would get the bounds of the screen, and then find the center of those bounds. If you have a GoogleMapController for the GoogleMap, just use a function like this:

    getCenter() async {
        LatLngBounds bounds = await mapsController.getVisibleRegion();
        LatLng center = LatLng(
          (bounds.northeast.latitude + bounds.southwest.latitude) / 2,
          (bounds.northeast.longitude + bounds.southwest.longitude) / 2,
        );
    
        return center;
      }