I am trying to make a navigation marker on google map, for the user location I am using geolocator pub dev with the listen function however it returned as a Position? and since it have the posibility of null, it can’t be used directly can anyone tell me how to do it ?
Position? listenToLocation()
{
Position? userposition;
final LocationSettings _locationSettings = LocationSettings(accuracy: LocationAccuracy.high,distanceFilter: 100);
userStreamlocation = Geolocator.getPositionStream(locationSettings: _locationSettings).listen(
(userposition) {
print(userposition == null ? 'Unknown' : '${userposition.latitude.toString()}, ${userposition.longitude.toString()}');
setState(){
streamResult=userposition;
}
});
return userposition;
}
3
Answers
I am able to fix this after finding out that the marker didn't got updated because it is in a different state than the main widget, I fix it trough the use of the statebuilder widget, here's the code snip
This way the googlemap have its own state and can be refreshed
Use onDragEnd functionality to drag the marker and release it and make sure u make ‘draggable’ true in the code given below….
late List dataMarkers = widget.apiDataArray.map((value) {
}).toList();
Try below,
In order to begin drag, you need to long press the marker
set ‘draggable’ as true on the marker.