谷歌地图和谷歌的地方扑扑

时间:2020-10-22 14:38:20

标签: flutter google-maps google-places

我将我的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, widget.lng),
              tilt: 30.0,
              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

0 个答案:

没有答案