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

GitHub 代码仓xantiagoma/google_maps_controller

google_maps_controller

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

google_maps_controller 项目封面
星标
5
复刻
2
最近推送(UTC)
2021年4月22日
项目状态
已归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

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>
Santiago Montoya A. GitHub avatar
GitHub 作者

Santiago Montoya A. ↗

Developer / EngineerMedellín, Colombia官方网站 ↗
语言DartRubySwiftKotlinObjective-C

此仓库发布的插件

使用的依赖

依赖清单 4 项

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗