我试图通过使用'geolocator'库来确定我的地址的相机位置,但我不知道如何将其设置为谷歌地图的初始相机位置
searchAndNavigate() {
searchAddress = widget.author.address;
Geolocator().placemarkFromAddress(searchAddress).then((result) {
mapController.animateCamera(CameraUpdate.newCameraPosition(CameraPosition(
target:
LatLng(result[0].position.latitude, result[0].position.longitude),
zoom: 10.0)));
});
}
void onMapCreated(controller) {
setState(() {
mapController = controller;
});
}
Widget mapSection = Container(
height: 400,
width: 400,
child: Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12.0)),
child: GoogleMap(
onMapCreated: onMapCreated,
initialCameraPosition: CameraPosition(
target: LatLng(40.7128, -74.0060), zoom: 10.0)),
),
);
@override
void initState() {
super.initState();
searchAndNavigate();
}