1

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..

BillRob
  • 4,659
  • 4
  • 26
  • 38
Merym
  • 731
  • 7
  • 18
  • Please check Stack Overflow community guidelines on [how to ask a question](https://stackoverflow.com/help/how-to-ask). – Abdelbaki Boukerche Jun 11 '20 at 21:58
  • @AbdelbakiBoukerche how to write a question ? – Merym Jun 11 '20 at 22:02
  • I didn't mean any offense but in order to have a chance for someone to answer your question you should follow Stack Overflow community guidelines on [how to ask](https://stackoverflow.com/help/how-to-ask). Please provide more informations. what did you tried ? Is there any error messages ? maybe your code or something that can help others to post an answer. Thanks for your understanding. – Abdelbaki Boukerche Jun 11 '20 at 22:11

2 Answers2

5

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;
  }
Alex Collette
  • 1,664
  • 13
  • 26
2

In the latest version of google maps flutter we can get the coordinates of location by passing in the screen coordinatinates,

// some code here

Size screen = MediaQuery.of(context).size;

// some code here

final coords = await mapController.getLatLng(ScreenCoordinate( x: screen.width/2, y: 
screen.width/2));
Muddassar
  • 349
  • 2
  • 13
  • there are two kinds of size one is logical that we normally get from MediaQuery.of(context).size and other is screen resolution now google maps getLang() takes screen resolution rather then logical size be aware when using it – Muddassar Jan 26 '23 at 09:59