How do you get the corners of the screen as geographical coordinates for Google Maps using Flutter

Viewed 48

I'm trying to get the corners of my screen, transform them into Points and pass them to my backend to then receive all the markers that fit my screen and place them on my map. The part I'm interested about is on how to get the corners of the screen.

I'm currently calculating corners onMapCreated: and after calculating that I place the markers

  void _onMapCreated(GoogleMapController controller) {
double screenWidth = MediaQuery.of(context).size.width *
    MediaQuery.of(context).devicePixelRatio;
double screenHeight = MediaQuery.of(context).size.height *
    MediaQuery.of(context).devicePixelRatio;

ScreenCoordinate northEast = ScreenCoordinate(x: screenWidth.round(), y: 0);
ScreenCoordinate southWest =
    ScreenCoordinate(x: 0, y: screenHeight.round());
LatLng northEastPoint = await controller.getLatLng(northEast);
LatLng southWestPoint = await controller.getLatLng(southWest);
  }

I think my issue right now is that I'm not taking into account the center of the map, regardless of my center the corners always are latMin: -25.27, latMax: -25.61, longMin: -57.566 and longMax: -57.560

my widget build so you can test

  static final CameraPosition _kGooglePlex = CameraPosition(
    target: LatLng(-25.265620626519592, -57.5632423825354),
    zoom: 16.5,
  );
      @override
      Widget build(BuildContext context) {
        return Scaffold(
          appBar: AppBar(
            title: Text('Test'),
          ),
          body: GoogleMap(
            initialCameraPosition: _kGooglePlex,
            markers: _markers,
            myLocationEnabled: true,
            onMapCreated: _onMapCreated,
          ),
          floatingActionButton: FloatingActionButton.extended(
            elevation: 0,
            onPressed: () {print('pressed')},
            backgroundColor: Color(0xE6FDBE83),
            label: Text('Report'),
            icon: Icon(Icons.add),
          ),
          floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
        );
      }
0 Answers
Related