I use these packages google_maps_flutter: ^2.2.3 flutter_polyline_points: ^1.0.0 location: ^4.4.0 The fact is that when I test on the emulator, this command works correctly. She's tracking tracking location
await location.getLocation().then((locationn) {
currentLocation = locationn;
});
When I test on a real device, this also works, but I need to enable geolocation in advance and log in to google maps. If I do not include geolocation in advance and request the user's location, this function will not work
Future<LocationData> getCurrentLocation() async {
Location location = Location();
try {
await location.getLocation().then((locationn) {
currentLocation = locationn;
});
location.onLocationChanged.listen(
(newLoc) {
currentLocation = newLoc;
},
);
} catch (e) {
print('т $e');
}
notifyListeners();
return currentLocation;}
the program stops here in this line and does not move any further. There are no error messages
await location.getLocation().then((locationn) {
I'm doing the main function in future builder. here you can see that the maps are not displayed because of Marker() which requires my map coordinates
(mapModel.currentLocation!.latitude!, mapModel.currentLocation!.longitude!)
.
However, the get Current Location() function cannot return the current Location variable because, as I said earlier, for some reason it stops at the line
await location.getLocation().then((locationn)
FutureBuilder<LocationData>(
future: mapModel.getCurrentLocation(),
builder:(context, snapshot){
if (snapshot.connectionState == ConnectionState.done) {
return GoogleMap(
markers: {
Marker(
markerId: const MarkerId("currentLocation"),
position: LatLng(mapModel.currentLocation!.latitude!,
mapModel.currentLocation!.longitude!),
)
},
position: LatLng(mapModel.currentLocation!.latitude!,
mapModel.currentLocation!.longitude!),
the manifest has all the necessary permissions
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />