【发布时间】:2019-06-09 23:54:39
【问题描述】:
如何使 Google 地图小部件在地图控制器进行更改时重新呈现?
@override
Widget build(BuildContext context) {
return GoogleMap(
onMapCreated: _onMapCreated,
options: GoogleMapOptions(
compassEnabled: true,
cameraPosition: CameraPosition(
target: LatLng(-36.8446085, 174.7547239),
zoom: 15.0,
),
),
);
}
该方法通过使用地图控制器进行更新,根据用户的当前位置添加标记和动画缩放。此方法由在此 google 地图渲染小部件的父小部件处触发 StreamController 的 FAB 运行。
void _populateUserLocation() {
_getLocation().then((location) {
setState(() {
userLocation = LatLng(location['latitude'], location['longitude']);
});
});
_mapController.addMarker(
MarkerOptions(
position: userLocation,
infoWindowText: InfoWindowText("!", "Your are here"),
)
);
_mapController.animateCamera(
CameraUpdate.newCameraPosition(
CameraPosition(
target: userLocation,
tilt: 50.0,
zoom: 20.0,
)
)
);
}
目前,这仅在第二台 FAB 印刷机上按预期工作。这意味着地图没有根据地图控制器所做的更改适当地重新渲染。
【问题讨论】:
-
您是否找到了解决地图在新位置重新渲染的好方法?
标签: google-maps dart flutter