问题描述
我将我的Flutter应用程序集成了google地图和地方,我为在多个屏幕中使用过的google地图创建了小部件
这是我的小部件
import 'package:joobike/utilities/size_confg.dart';
class MapField extends StatefulWidget {
final double lat,lng;
final List<Marker> markers;
MapField({this.lat,this.lng,this.markers});
@override
_MapFieldState createState() => _MapFieldState();
}
class _MapFieldState extends State<MapField> {
@override
Widget build(BuildContext context) {
CameraPosition _kGoogleAddress = CameraPosition(
bearing: 270.0,tilt: 30.0,target: new LatLng(widget.lat,widget.lng),zoom: 14.4746,);
return Container(
width: double.infinity,height: getProportionateScreenHeight(200),child: GoogleMap(
mapToolbarEnabled: true,onMapCreated: (GoogleMapController controller) {
setState(() {
controller.moveCamera(CameraUpdate.newCameraPosition(CameraPosition(
bearing: 270,target: LatLng(widget.lat,zoom: 17.0,)));
});
},initialCameraPosition: _kGoogleAddress,markers: Set.from(widget.markers),mapType: MapType.normal,),);
}
}
在其他窗口小部件中,我使用了此窗口小部件来显示地图以及此处有助于调用此窗口小部件的功能代码
try {
PlacesDetailsResponse detail = await _placesDetailsResponse();
setState(() {
lat = detail.result.geometry.location.lat;
lng = detail.result.geometry.location.lng;
markers.add(Marker(
markerId: MarkerId(LatLng(lat,lng).toString()),position: LatLng(lat,lng)));
});
} catch (error) {
print(error);
}
}```
my problem is when i call this function when i pressed on button the map work good but if i pressed again and choose different place the map still same didn't change so i asked for a way to change the map to the new place when i press on button again
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)