如何使用Flutter在Google地图上调整多边形的大小?

时间:2019-07-04 13:29:00

标签: google-maps flutter dart

我正在使用google_maps_flutter包来使用google地图并添加多边形。我想调整/调整多边形的大小以获取正确的区域。

我尝试搜索要调整的任何属性,但没有找到。

这是我将多边形添加到Google地图的代码。

Widget build(BuildContext context) {
 return MaterialApp(
   home: Scaffold(
     appBar: AppBar(
       title: Text('Maps Sample App'),
       backgroundColor: Colors.green[700],
       actions: <Widget>[
         IconButton(
             icon: Icon(Icons.call_made),
             tooltip: 'Sign Out',
             onPressed: _signOut),
       ],
     ),
     body: Container(
       height: MediaQuery.of(context).size.height,
       width: MediaQuery.of(context).size.width,
       child: GoogleMap(
           onMapCreated: _onMapCreated,
           initialCameraPosition: CameraPosition(
             target: LatLng(widget.location.first.latitude,
                 widget.location.first.longitude),
             zoom: 11.0,
           ),
                 polygons: Set<Polygon>.of(<Polygon>[
             Polygon(
               polygonId: PolygonId('area'),
       points: _points,
       geodesic: true,
       strokeColor: Colors.blue,
       fillColor: Colors.lightBlue.withOpacity(0.1),
       visible: true
             )
           ]),
           markers: Set<Marker>.of(<Marker>[
             Marker(
                 markerId: MarkerId('1'),
                 position: LatLng(widget.location.first.latitude,
                     widget.location.first.longitude),
                 visible: true,
                 draggable: true)
           ])),
     ),
   ),
 );
}

如何通过拖动顶点来调整多边形的大小?

1 个答案:

答案 0 :(得分:0)

据我所知,多边形是不可变的。您必须创建一个新的多边形并将其添加到多边形集中。

我使用带有onDragEnd的Marker来完成。该功能将接收标记的新位置。我使用标记位置来创建多边形的位置。

您可以在google_maps_flutter的example directory中检查place_marker.dat,以了解如何动态放置标记。就我而言,我使用的是GoogleMap的onLongPress(而不是按钮)来添加标记。

相关问题