搜索插件、代码仓与 APP 分类

google_maps_controller 封面
插件详情v1.2.0

google_maps_controller

Google Maps google_maps_flutter 的有状态地图控制器。用于管理标记、圆圈、折线和多边形。

AndroidiOSWeb
近 30 天下载
32
喜欢数
23
Pub 分数
140

安装插件

flutter pub add google_maps_controller

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个用于 Flutter 中 Google 地图的状态化地图控制器,旨在管理标记、圆圈、折线和多边形等交互式地图元素。它扩展了 google_maps_flutter 的功能,提供了一种更结构化且响应式的地图状态和更新处理方式。适用于需要动态地图交互的应用程序,例如位置跟踪、路线可视化或地理空间数据展示。该控制器确保 UI 与地图数据之间的顺畅协调,提高可维护性和响应速度。

适合场景

  • 实时位置跟踪
  • 带折线的路线可视化
  • 交互式标记管理
  • 地理空间数据叠加
  • 基于地图的分析仪表板

主要特点

  • 有状态的地图控件
  • 动态标记和形状管理
  • 地图元素的响应式更新
  • 与 google_maps_flutter 的轻松集成
  • 支持 Android、iOS 和 Web

适合对象

  • 开发交互式地图的开发者
  • 需要实时地图更新的应用
  • 位置感知应用
  • 跨平台地图解决方案
  • 带有多个叠加层的复杂地图UI

使用建议

  • 需要 google_maps_flutter 依赖
  • 可能增加应用大小
  • 地图初始化需要适当的错误处理
  • 仅限 Google 地图平台
  • Web 支持可能存在性能限制

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

google_maps_controller

Stateful map controller for Google Maps google_maps_flutter. Manage Markers, Circles, Polylines, and Polygons.

Inspired by map_controller for flutter_map.

Getting Started

Follow same config steps as decirbed in google_maps_flutter getting-started.

Usage

Use GoogleMaps widget instead of GoogleMap to use auto set-up widget.

Use GoogleMapsController for all the actions.

Check example dir for more details.

var controller = GoogleMapsController();

// Widget
GoogleMaps(
    controller: controller,
)

You can also provide controller through provider / InheritedWidget / BLoC or any other state management.

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:google_maps_controller/google_maps_controller.dart';

void main() {
  runApp(ExampleApp());
}

class ExampleApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Google Maps Controller Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: Scaffold(
        body: HomeScreen(),
      ),
    );
  }
}

class HomeScreen extends StatefulWidget {
  HomeScreen({Key key}) : super(key: key);

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

class _HomeScreenState extends State<HomeScreen> {
  final s = "Map 2";
  GoogleMapsController controller;
  StreamSubscription<CameraPosition> subscription;
  CameraPosition position;

  @override
  void initState() {
    super.initState();

    controller = GoogleMapsController(
      initialCameraPosition: CameraPosition(
        target: LatLng(37.42796133580664, -122.085749655962),
        zoom: 14.4746,
      ),
      onTap: (latlng) {
        Circle circle;
        circle = Circle(
          circleId: CircleId(
            "ID:" + DateTime.now().millisecondsSinceEpoch.toString(),
          ),
          center: latlng,
          fillColor: Color.fromRGBO(255, 0, 0, 1),
          strokeColor: Color.fromRGBO(155, 0, 0, 1),
          radius: 5,
          onTap: () => controller.removeCircle(circle),
          consumeTapEvents: true,
        );

        controller.addCircle(circle);
      },
    );

    subscription = controller.onCameraMove$.listen((e) {
      setState(() {
        position = e;
      });
    });
  }

  @override
  void dispose() {
    subscription.cancel();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        Expanded(
          child: GoogleMaps(
            controller: controller,
          ),
        ),
        SafeArea(
          top: false,
          child: Text("$position"),
        )
      ],
    );
  }
}

Demo

LICENSE

MIT

API

Check full docs

GoogleMapsController
GoogleMapsController({
    void Function(GoogleMapController) onMapCreated,
    void Function() onCameraIdle,
    void Function(CameraPosition) onCameraMove,
    void Function() onCameraMoveStarted,
    void Function(LatLng) onLongPress,
    void Function(LatLng) onTap,
    CameraPosition initialCameraPosition,
    Set<Circle> initialCircles,
    Set<Marker> initialMarkers,
    Set<Polygon> initialPolygons,
    Set<Polyline> initialPolylines,
    bool buildingsEnabled,
    CameraTargetBounds cameraTargetBounds,
    bool compassEnabled,
    bool indoorViewEnabled,
    bool liteModeEnabled,
    bool zoomControlsEnabled,
    bool mapToolbarEnabled,
    MapType mapType,
    MinMaxZoomPreference minMaxZoomPreference,
    bool myLocationEnabled,
    bool myLocationButtonEnabled,
    EdgeInsets padding,
    bool rotateGesturesEnabled,
    bool scrollGesturesEnabled,
    bool tiltGesturesEnabled,
    bool trafficEnabled,
    bool zoomGesturesEnabled,
    List<Factory<OneSequenceGestureRecognizer>> gestureRecognizers,
});
GoogleMaps
GoogleMaps({
    @required GoogleMapsController controller,
})
Controller
Properties
buildingsEnabled ↔ bool
cameraTargetBounds ↔ CameraTargetBounds
circles ↔ Set<Circle>
compassEnabled ↔ bool
context → BuildContext
controller → GoogleMapController
gestureRecognizers ↔ Set<Factory<OneSequenceGestureRecognizer>>
indoorViewEnabled ↔ bool
initialCameraPosition → CameraPosition
initted → bool
liteModeEnabled ↔ bool
mapToolbarEnabled ↔ bool
mapType ↔ MapType
markers ↔ Set<Marker>
minMaxZoomPreference ↔ MinMaxZoomPreference
myLocationButtonEnabled ↔ bool
myLocationEnabled ↔ bool
onCameraIdle → void Function()
onCameraIdle$ → Stream<void>
onCameraMove → void Function(CameraPosition)
onCameraMove$ → Stream<CameraPosition>
onCameraMoveStarted → void Function()
onCameraMoveStarted$ → Stream<void>
onLongPress → void Function(LatLng)
onLongPress$ → Stream<LatLng>
onMapCreated → void Function(GoogleMapController)
onTap → void Function(LatLng)
onTap$ → Stream<LatLng>
padding ↔ EdgeInsets
polygons ↔ Set<Polygon>
polylines ↔ Set<Polyline>
rotateGesturesEnabled ↔ bool
scrollGesturesEnabled ↔ bool
tiltGesturesEnabled ↔ bool
trafficEnabled ↔ bool
zoom → Future<double>
zoomControlsEnabled ↔ bool
zoomGesturesEnabled ↔ bool
Methods
addCircle(Circle circle) → void
addCircles(List<Circle> circles) → void
addMarker(Marker marker) → void
addMarkers(List<Marker> markers) → void
addPolygon(Polygon polygon) → void
addPolygons(List<Polygon> polygons) → void
addPolyline(Polyline polyline) → void
addPolylines(List<Polyline> polylines) → void
animateCamera(CameraUpdate cameraUpdate) → Future<void>
clearCircles() → void
clearMarkers() → void
clearPolygons() → void
clearPolylines() → void
getLatLng(ScreenCoordinate screenCoordinate) → Future<LatLng>
getScreenCoordinate(LatLng latLng) → Future<ScreenCoordinate>
getVisibleRegion() → Future<LatLngBounds>
getZoomLevel() → Future<double>
hideMarkerInfoWindow(MarkerId markerId) → Future<double>
init(GoogleMapController controller) → void
isMarkerInfoWindowShown(MarkerId markerId) → Future<bool>
moveCamera(CameraUpdate cameraUpdate) → Future<void>
newCameraPosition(CameraPosition cameraPosition, {bool animate: false}) → Future<void>
newLatLng(LatLng latLng, {bool animate: false}) → Future<void>
newLatLngBounds(LatLngBounds bounds, double padding, {bool animate: false}) → Future<void>
newLatLngZoom(LatLng latLng, double zoom, {bool animate: false}) → Future<void>
removeCircle(Circle circle) → void
removeCircles(Iterable<Circle> circles) → void
removeMarker(Marker marker) → void
removeMarkers(Iterable<Marker> markers) → void
removePolygon(Polygon polygon) → void
removePolygons(Iterable<Polygon> polygons) → void
removePolyline(Polyline polyline) → void
removePolylines(Iterable<Polyline> polylines) → void
scrollBy(double dx, double dy, {bool animate: false}) → Future<void>
setContext(BuildContext context) → void
setMapStyle(String mapStyle) → Future<void>
showMarkerInfoWindow(MarkerId markerId) → Future<bool>
takeSnapshot() → Future<Uint8List>
updateCamera(CameraUpdate cameraUpdate, {bool animate: false}) → Future<void>
zoomBy(double amount, {Offset focus, bool animate: false}) → Future<void>
zoomIn({bool animate: false}) → Future<void>
zoomOut({bool animate: false}) → Future<void>
zoomTo(double zoom, {bool animate: false}) → Future<void>

所属分类

依赖

依赖清单 2 项

源码仓库

使用此插件的项目

暂无相关数据。