I want to load my google maps on flutter app to my current location.
the code i used is..
late LatLng _center;
late Position currentLocation;
@override
void initState() {
super.initState();
getUserLocation();
}
Future<Position> locateUser() async {
return Geolocator.getCurrentPosition(
desiredAccuracy: LocationAccuracy.high);
}
getUserLocation() async {
currentLocation = await locateUser();
setState(() {
_center = LatLng(currentLocation.latitude, currentLocation.longitude);
});
print('center $_center');
}
static const CameraPosition _MyPostn = CameraPosition(
target:_center,
zoom: 14.4746,
);
What am I doing wrong here?
I did search other similar questions but didn't find any solution.