'My Google Maps implementation goes back after a few seconds to my current location
I am new at using Flutter and I am implementing Google Maps in my app. The thing is that i implemented a function to get my current location and make the camera move to that position, and I only want to travel to my current location whenever i tap on a FloatingActionButton. The only moment i call these function that gets to my location is when i tap that button, but if im not touching the app, after a few seconds, it redirects to my current location automatically, and i would like to change that so it stops travelling by itself. Here's the implementation related to the Google Maps thing. Thanks!
class _MapScreenState extends State<MapScreen> {
GoogleMapController? _controller;
Location currentLocation = Location();
Set<Marker> _markers = {};
void getLocation() async {
var location = await currentLocation.getLocation();
currentLocation.onLocationChanged.listen((LocationData loc) {
_controller
?.animateCamera(CameraUpdate.newCameraPosition(new CameraPosition(
target: LatLng(loc.latitude ?? 0.0, loc.longitude ?? 0.0),
zoom: 16.0,
)));
print(loc.latitude);
print(loc.longitude);
setState(() {
_markers.add(Marker(
markerId: MarkerId('Home'),
position: LatLng(loc.latitude ?? 0.0, loc.longitude ?? 0.0)));
});
});
}
@override
void initState() {
super.initState();
setState(() {
getLocation();
});
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
