Reputation: 440
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
Upvotes: 2
Views: 2101
Reputation: 308
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;
}
)
Upvotes: 6