1

How to configure google_maps_flutter in Flutter in oder to keep the marker in the center of the map while user will drag the map and get new position with new latitude and longitude, e.g. Uber

enter image description here

Andrew Piterov
  • 340
  • 3
  • 12

1 Answers1

3

Put your GoogleMap inside Stack then put your cursor widget in the Center on the top of your GoogleMap as follow:

  Stack(
    children: [
      GoogleMap(),
      Center(child: CursorrWidget()),
    ],
  );

To calculate your cursor latitude and longitude call this function when notifying onCameraIdle:

GoogleMap(
  onCameraIdle: () {
    LatLngBounds bounds = mapController.getVisibleRegion();
    final lon = (bounds.northeast.longitude + bounds.southwest.longitude) / 2;
    final lat = (bounds.northeast.latitude + bounds.southwest.latitude) / 2;
  }
)