修复谷歌地图标记在中心

修复谷歌地图标记在中心,第1张

修复谷歌地图标记在中心

实际上,通过google_maps_flutter的新更新:^
0.4.0,
我们可以轻松实现上述要求。

这是演示链接。

Map<MarkerId, Marker> _markers = <MarkerId, Marker>{};int _markerIdCounter = 0;Completer<GoogleMapController> _mapController = Completer();Container(    width: MediaQuery.of(context).size.width,    height: MediaQuery.of(context).size.height,    child: GoogleMap(      markers: Set<Marker>.of(_markers.values),      onMapCreated: _onMapCreated,      initialCameraPosition: CameraPosition(        target: Constants.LOCATION_SRI_LANKA,        zoom: 12.0,      ),      myLocationEnabled: true,      onCameraMove: (CameraPosition position) {        if(_markers.length > 0) {          MarkerId markerId = MarkerId(_markerIdVal());          Marker marker = _markers[markerId];          Marker updatedMarker = marker.copyWith( positionParam: position.target,          );          setState(() { _markers[markerId] = updatedMarker;          });        }      },    ),  )void _onMapCreated(GoogleMapController controller) async {  _mapController.complete(controller);  if ([INITIAL_LOCATION] != null) {    MarkerId markerId = MarkerId(_markerIdVal());    LatLng position = [INITIAL_LOCATION];    Marker marker = Marker(      markerId: markerId,      position: position,      draggable: false,    );    setState(() {      _markers[markerId] = marker;    });    Future.delayed(Duration(seconds: 1), () async {      GoogleMapController controller = await _mapController.future;      controller.animateCamera(        CameraUpdate.newCameraPosition(          CameraPosition( target: position, zoom: 17.0,          ),        ),      );    });  }}String _markerIdVal({bool increment = false}) {  String val = 'marker_id_$_markerIdCounter';  if (increment) _markerIdCounter++;  return val;}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5016632.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-14
下一篇 2022-11-14

发表评论

登录后才能评论

评论列表(0条)

保存