To display a Custom Info Window on a Google Map in Flutter, you need to follow these steps:
dependencies:
google_maps_flutter: ^1.1.1
import 'package:google_maps_flutter/google_maps_flutter.dart';
GoogleMap(
initialCameraPosition: CameraPosition(target: LatLng(37.4220, -122.0841), zoom: 15),
markers: Set<Marker>.of(markers.values),
onMapCreated: (GoogleMapController controller) {
_controller.complete(controller);
},
onTap: (LatLng latLng) {
_showMarkerInfoWindow(null);
},
),
void _showMarkerInfoWindow(MarkerId markerId) {
if (markerId != null && markers.containsKey(markerId)) {
final Marker marker = markers[markerId];
setState(() {
selectedMarker = marker;
showInfoWindow = true;
});
} else {
setState(() {
selectedMarker = null;
showInfoWindow = false;
});
}
}
Widget _buildCustomInfoWindow(BuildContext context) {
if (!showInfoWindow || selectedMarker == null) {
return SizedBox.shrink();
}
return Align(
alignment: Alignment.topCenter,
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10.0),
color: Colors.white,
),
width: 300,
height: 100,
child: Center(
child: Text(selectedMarker.title),
),
),
);
}
Stack(
children: <Widget>[
GoogleMap(
...
),
_buildCustomInfoWindow(context),
],
);
These are the basic steps to create and display a Custom Info Window on a Google Map in Flutter.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-07-13 14:06:42 +0000
Seen: 14 times
Last updated: Jul 13 '23
How can zooming similar to desktop be achieved in HTML webview browser using Flutter?
In what way can the appleID signin be utilized in flutter?
How to maintain state across different pages using flutter?
How can I change a CameraImage Stream into bytes or a file in Flutter?
How can the current page context be obtained by a Flutter GetX controller?