问题描述
我在 Flutter 应用程序的表单中使用 Flutter_map,但无法将地图居中。地图只显示了一片海洋。那是因为我的后备值(坐标)是 0,0。然后标记从 value[0] 和 value1 更新到正确的位置,但中心没有更新。
new FlutterMap(
options: new MapOptions(
// Todo: Center doesn't refresh
// https://github.com/fleaflet/Flutter_map/issues/10
center: new latlong.LatLng(value[0],value[1]),zoom: 13.0,),layers: [
new TileLayerOptions(urlTemplate: "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",subdomains: ['a','b','c']),new MarkerLayerOptions(
markers: [
new Marker(
width: 20.0,height: 20.0,point: new latlong.LatLng(value[0],builder: (ctx) => new Container(
child: Icon(
Icons.location_on,color: primaryColor,],
我不知道为什么 center: new latlong.LatLng(value[0],
不起作用。有人可以帮我吗?这是 Flutter 包:https://pub.dev/packages/flutter_map
解决方法
参数“center”只会在启动时使用,不会更新。
您必须使用控制器才能移动到新位置。
https://pub.dev/documentation/flutter_map/latest/flutter_map/MapController-class.html
初始化您的控制器并将其添加到您的 FlutterMap
FlutterMap(controller:myController)