首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >颤振火基clustering_google_maps

颤振火基clustering_google_maps
EN

Stack Overflow用户
提问于 2019-04-13 05:00:01
回答 1查看 776关注 0票数 0

其目标是利用内存中的信息,使用集群生成谷歌地图标记。目前,我正在下载LATLNG点从Firebase到本地内存。接下来,我们的目标是使用Google集群功能在地图上显示这些点的集合。为此,有一个名为clustering_google_maps 0.0.4+2的依赖项,它允许从本地数据库(SQLite)或本地内存访问数据。

开发人员建议使用数千个大型标记集,最好使用本地数据库(SQLite)。在我的例子中,我只有20-40个标记。有人能提供一个解决方案来解释如何使用本地内存的数据在Google上显示吗?

回购的快速例子

代码语言:javascript
复制
class HomeScreen extends StatefulWidget {
  final List<LatLngAndGeohash> list;

  HomeScreen({Key key, this.list}) : super(key: key);

  @override
  _HomeScreenState createState() => _HomeScreenState();
}

class _HomeScreenState extends State<HomeScreen> {
  ClusteringHelper clusteringHelper;
  final CameraPosition initialCameraPosition =
      CameraPosition(target: LatLng(0.000000, 0.000000), zoom: 0.0);

  Set<Marker> markers = Set();

  void _onMapCreated(GoogleMapController mapController) async {
    print("onMapCreated");
    if (widget.list == null) {
      clusteringHelper.database = await AppDatabase.get().getDb();
    }
    clusteringHelper.updateMap();
  }

  updateMarkers(Set<Marker> markers) {
    setState(() {
      this.markers = markers;
    });
  }

  @override
  void initState() {
    if (widget.list != null) {
      initMemoryClustering();
    } else {
      initDatabaseClustering();
    }

    super.initState();
  }

  // For db solution
  initDatabaseClustering() {
    clusteringHelper = ClusteringHelper.forDB(
      dbGeohashColumn: FakePoint.dbGeohash,
      dbLatColumn: FakePoint.dbLat,
      dbLongColumn: FakePoint.dbLong,
      dbTable: FakePoint.tblFakePoints,
      updateMarkers: updateMarkers,
    );
  }

  // For memory solution
  initMemoryClustering() {
    clusteringHelper = ClusteringHelper.forMemory(
      list: widget.list,
      updateMarkers: updateMarkers,
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Clustering Example"),
      ),
      body: GoogleMap(
        onMapCreated: _onMapCreated,
        initialCameraPosition: initialCameraPosition,
        markers: markers,
        onCameraMove: (newPosition) => clusteringHelper.onCameraMove(newPosition, forceUpdate: false),
        onCameraIdle: clusteringHelper.onMapIdle,
      ),
      floatingActionButton: FloatingActionButton(
        child:
            widget.list == null ? Icon(Icons.content_cut) : Icon(Icons.update),
        onPressed: () {
          if (widget.list == null) {
            clusteringHelper.whereClause = "WHERE ${FakePoint.dbLat} > 42.6";
            clusteringHelper.updateMap();
          } else {
            clusteringHelper.updateMap();
          }
        },
      ),
    );
  }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-04-17 18:01:54

从医生那里

内存技术要正常工作,您必须有一个LatLngAndGeohash对象的列表。LatLngAndGeohash是一个带有Location和Geo散列属性的简单对象,最后一个是自动生成的;您只需要点的位置。 对于此解决方案,必须使用ClusteringHelper的内存构造函数:

代码语言:javascript
复制
ClusteringHelper.forMemory(...);

要测试这个特性,您可以克隆地图回购。然后使用以下代码修改splash.dart文件。从HomeScreen调用splash.dart时

代码语言:javascript
复制
  List<LatLngAndGeohash> markerList = new List<LatLngAndGeohash>();

  @override
  void initState() {
    super.initState();
    markerList.add(LatLngAndGeohash(LatLng(34.0522, -118.2437)));
    markerList.add(LatLngAndGeohash(LatLng(34.0522, -118.2647)));
    markerList.add(LatLngAndGeohash(LatLng(34.0522, -118.2467)));
    markerList.add(LatLngAndGeohash(LatLng(34.0522, -118.2487)));
    markerList.add(LatLngAndGeohash(LatLng(34.0522, -118.2707)));
  }

 @override
   Widget build(BuildContext context) {
     return Scaffold(
        ....
        HomeScreen(list: markerList)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55662174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档