Performance 如何优化应用程序以在Flitter中有效地在google地图上显示更多标记?

Performance 如何优化应用程序以在Flitter中有效地在google地图上显示更多标记?,performance,google-maps,flutter,optimization,google-maps-api-3,Performance,Google Maps,Flutter,Optimization,Google Maps Api 3,我正在做一个项目,在这个项目中,我必须从数据库在地图上显示标记。在数据库中,我有大约6000多个客户的数据,我想在地图上用纬度和经度显示这些信息。问题是,当只有5-10个客户的记录时,应用程序不会减速,但当我在地图上显示数千个标记时,应用程序开始滞后。有没有更好的办法来解决这个问题 在地图上显示标记的代码 _onMapCreated() async { // print(customerInfo); for (var item in ud.customerInfo) {

我正在做一个项目,在这个项目中,我必须从数据库在地图上显示标记。在数据库中,我有大约6000多个客户的数据,我想在地图上用纬度和经度显示这些信息。问题是,当只有5-10个客户的记录时,应用程序不会减速,但当我在地图上显示数千个标记时,应用程序开始滞后。有没有更好的办法来解决这个问题

在地图上显示标记的代码

_onMapCreated() async {
    // print(customerInfo);
    for (var item in ud.customerInfo) {
      if (item['customer_latitude'] == "" && item['customer_longitude'] == "") {
        continue;
      } else {
        final MarkerId markerId = MarkerId((markers.length + 1).toString());
        LatLng markerPos = LatLng(double.parse(item['customer_latitude']),
            double.parse(item['customer_longitude']));
        final Marker marker = Marker(
            infoWindow: InfoWindow(
              title: item['customer_name'],
              snippet: item['customer_desc'],
            ),
            // onTap: () => _onMarkerTapped(markerId),
            icon: BitmapDescriptor.defaultMarkerWithHue(
                item['customer_status'] == 'red'
                    ? BitmapDescriptor.hueRed
                    : item['customer_status'] == 'yellow'
                        ? BitmapDescriptor.hueYellow
                        : BitmapDescriptor.hueGreen),
            markerId: markerId,
            consumeTapEvents: true,
            position: markerPos,
            onTap: () {
              Navigator.push(
                  context,
                  MaterialPageRoute<Null>(
                    builder: (BuildContext context) {
                      return CustomerDetail(
                          item['customer_id'],
                          item['customer_name'],
                          item['customer_email'],
                          item['customer_desc'],
                          item['customer_phone'],
                          item['customer_status']);
                    },
                    fullscreenDialog: true,
                  ));
            });
        _markers = null;
        markers[markerId] = marker;
      }
    }
    setState(() {});
  }
\u onmacreated()异步{
//打印(客户信息);
对于(ud.customerInfo中的变量项){
如果(项目['customer\u latitude']==”&项目['customer\u latitude']==”){
继续;
}否则{
final MarkerId MarkerId=MarkerId((markers.length+1.toString());
LatLng MAKERPOS=LatLng(double.parse(项['customer\u latitude']),
double.parse(项目['customer_longitude']);
最终标记=标记(
信息窗口:信息窗口(
标题:项目[“客户名称”],
代码片段:项['customer_desc'],
),
//onTap:()=>(在MarkerTapped(markerId)上),
图标:BitmapDescriptor.defaultMarkerWithHue(
项目['customer_status']=“红色”
?BitmapDescriptor.hueRed
:项目['customer_status']=“黄色”
?BitmapDescriptor.huyellow
:BitmapDescriptor.hueGreen),
马克里德:马克里德,
对,,
职位:markerPos,
onTap:(){
导航器。推(
上下文
材料路线(
生成器:(BuildContext上下文){
返回客户详细信息(
项目['customer_id'],
项目[‘客户名称’],
项目['customer_email'],
项目[“客户描述”],
项目[“客户电话”],
项目[“客户状态]);
},
fullscreenDialog:true,
));
});
_标记=空;
markers[markerId]=标记器;
}
}
setState((){});
}

还有一点,数据已经从数据库中提取并存储在列表中,因此在循环过程中,它只是从列表中获取数据并将其呈现在google maps上。

在Flitter中呈现google map中的数千个标记尚未优化,我认为您需要进行聚类来解决此问题,类似这样的事情: