Clustering Support in Google Map Flutter 2024
The much-anticipated clustering feature in Google Maps Flutter is finally live! On August 7th, the pull request was merged into the main branch, introducing the clustering functionality in version 2.9.0 of the google_maps_flutter
package.
So to add clustering in marker we just need to add clusterManagerId property in Marker.
Adding Full Source code below-
import 'dart:math';
import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';
GlobalKey<NavigatorState>? navigatorKey;
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key,}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
navigatorKey: navigatorKey,
debugShowCheckedModeBanner: false,
home: const GoogleMapClustering(),
);
}
}
class GoogleMapClustering extends StatefulWidget {
const GoogleMapClustering({super.key});
@override
State<StatefulWidget> createState() => GoogleMapClusteringState();
}
class GoogleMapClusteringState extends State<GoogleMapClustering> {…