Home > front end >  How to make Google map draggable and keep marker in the center of the screen on Flutter?
How to make Google map draggable and keep marker in the center of the screen on Flutter?

Time:08-12

How to configure enter image description here

CodePudding user response:

For draggable you should use setOptions

map.setOptions({draggable: true});

and for marker in center

marker.setPosition( map.getCenter(););

CodePudding user response:

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;
  }
)
  • Related